1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Create hstore From Two Arrays as a postgres til.

This commit is contained in:
jbranchaud
2015-12-23 13:50:11 -06:00
parent 531175dbca
commit 660782e55e
2 changed files with 21 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
# Create hstore From Two Arrays
PostgreSQL allows the use of the `hstore` type by enabling the `hstore`
extension. One way to create an instance of `hstore` data is by passing two
arrays to the `hstore()` function. The first array is a set of keys and the
second array is the set of values.
```sql
> select hstore(array['one','two','three'], array['1','2','3']);
hstore
--------------------------------------
"one"=>"1", "two"=>"2", "three"=>"3"
```
The two arrays must be the same length or an error will occur.
```sql
> select hstore(array['one','two','three'], array['1','2']);
ERROR: arrays must have same bounds
```