summaryrefslogtreecommitdiff
path: root/contrib/hstore/sql/hstore.sql
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-12-11 18:58:07 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-12-11 18:58:21 -0500
commit0ec5f7e78231a621a1d96c4bfedc4a1849a6c6cc (patch)
treeb405c93112e30c7cdeeb5d0fa6bc4e318fd2056e /contrib/hstore/sql/hstore.sql
parent8c15a297452e970d68529ee2ce6bd94d84598409 (diff)
downloadpostgresql-0ec5f7e78231a621a1d96c4bfedc4a1849a6c6cc.tar.gz
Allow subscripting of hstore values.
This is basically a finger exercise to prove that it's possible for an extension module to add subscripting ability. Subscripted fetch from an hstore is not different from the existing "hstore -> text" operator. Subscripted update does seem to be a little easier to use than the traditional update method using hstore concatenation, but it's not a fundamentally new ability. However, there may be some value in the code as sample code, since it shows what's basically the minimum-complexity way to implement subscripting when one needn't consider nested container objects. Discussion: https://postgr.es/m/3724341.1607551174@sss.pgh.pa.us
Diffstat (limited to 'contrib/hstore/sql/hstore.sql')
-rw-r--r--contrib/hstore/sql/hstore.sql8
1 files changed, 8 insertions, 0 deletions
diff --git a/contrib/hstore/sql/hstore.sql b/contrib/hstore/sql/hstore.sql
index a6c2f3a0ce..8d96e30403 100644
--- a/contrib/hstore/sql/hstore.sql
+++ b/contrib/hstore/sql/hstore.sql
@@ -364,6 +364,14 @@ insert into test_json_agg values ('rec1','"a key" =>1, b => t, c => null, d=> 12
select json_agg(q) from test_json_agg q;
select json_agg(q) from (select f1, hstore_to_json_loose(f2) as f2 from test_json_agg) q;
+-- Test subscripting
+insert into test_json_agg default values;
+select f2['d'], f2['x'] is null as x_isnull from test_json_agg;
+select f2['d']['e'] from test_json_agg; -- error
+select f2['d':'e'] from test_json_agg; -- error
+update test_json_agg set f2['d'] = f2['e'], f2['x'] = 'xyzzy';
+select f2 from test_json_agg;
+
-- Check the hstore_hash() and hstore_hash_extended() function explicitly.
SELECT v as value, hstore_hash(v)::bit(32) as standard,
hstore_hash_extended(v, 0)::bit(32) as extended0,