mirror of
https://github.com/jbranchaud/til
synced 2026-01-08 01:28:02 +00:00
Add Create hstore From Two Arrays as a postgres til.
This commit is contained in:
@@ -121,6 +121,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
- [Configure The Timezone](postgres/configure-the-timezone.md)
|
- [Configure The Timezone](postgres/configure-the-timezone.md)
|
||||||
- [Count Records By Type](postgres/count-records-by-type.md)
|
- [Count Records By Type](postgres/count-records-by-type.md)
|
||||||
- [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md)
|
- [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md)
|
||||||
|
- [Create hstore From Two Arrays](postgres/create-hstore-from-two-arrays.md)
|
||||||
- [Default Schema](postgres/default-schema.md)
|
- [Default Schema](postgres/default-schema.md)
|
||||||
- [Defining Arrays](postgres/defining-arrays.md)
|
- [Defining Arrays](postgres/defining-arrays.md)
|
||||||
- [Edit Existing Functions](postgres/edit-existing-functions.md)
|
- [Edit Existing Functions](postgres/edit-existing-functions.md)
|
||||||
|
|||||||
20
postgres/create-hstore-from-two-arrays.md
Normal file
20
postgres/create-hstore-from-two-arrays.md
Normal 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
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user