summaryrefslogtreecommitdiff
path: root/contrib/hstore
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-09-10 17:36:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-09-10 17:36:52 +0000
commit684ad6a92fcc33adebdab65c4e7d72a68ba05408 (patch)
tree4cd0fc427b2100214e18452cc528e1b2e2d150fb /contrib/hstore
parentba920e1c9182eac55d5f1327ab0d29b721154277 (diff)
downloadpostgresql-684ad6a92fcc33adebdab65c4e7d72a68ba05408.tar.gz
Rename contrib contains/contained-by operators to @> and <@, per discussion.
Diffstat (limited to 'contrib/hstore')
-rw-r--r--contrib/hstore/README.hstore16
-rw-r--r--contrib/hstore/expected/hstore.out43
-rw-r--r--contrib/hstore/hstore.sql.in35
-rw-r--r--contrib/hstore/sql/hstore.sql40
4 files changed, 85 insertions, 49 deletions
diff --git a/contrib/hstore/README.hstore b/contrib/hstore/README.hstore
index 94379e9eb4..601ae49259 100644
--- a/contrib/hstore/README.hstore
+++ b/contrib/hstore/README.hstore
@@ -46,23 +46,29 @@ select 'a'=>'b';
----------
"a"=>"b"
- * hstore @ hstore - contains operation, check if left operand contains right.
+ * hstore @> hstore - contains operation, check if left operand contains right.
-regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
+regression=# select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
?column?
----------
f
(1 row)
-regression=# select 'a=>b, b=>1, c=>NULL'::hstore @ 'b=>1';
+regression=# select 'a=>b, b=>1, c=>NULL'::hstore @> 'b=>1';
?column?
----------
t
(1 row)
- * hstore ~ hstore - contained operation, check if left operand is contained
+ * hstore <@ hstore - contained operation, check if left operand is contained
in right
+(Before PostgreSQL 8.2, the containment operators @> and <@ were
+respectively called @ and ~. These names are still available, but are
+deprecated and will eventually be retired. Notice that the old names
+are reversed from the convention formerly followed by the core geometric
+datatypes!)
+
Functions
* akeys(hstore) - returns all keys from hstore as array
@@ -129,7 +135,7 @@ regression=# select isdefined('a=>NULL','a');
Indices
-Module provides index support for '@' and '~' operations.
+Module provides index support for '@>' and '<@' operations.
create index hidx on testhstore using gist(h);
diff --git a/contrib/hstore/expected/hstore.out b/contrib/hstore/expected/hstore.out
index 06605e1648..61c96a4b97 100644
--- a/contrib/hstore/expected/hstore.out
+++ b/contrib/hstore/expected/hstore.out
@@ -1,10 +1,11 @@
+--
+-- first, define the datatype. Turn off echoing so that expected file
+-- does not depend on contents of hstore.sql.
+--
+SET client_min_messages = warning;
\set ECHO none
-psql:hstore.sql:8: NOTICE: type "hstore" is not yet defined
-DETAIL: Creating a shell type definition.
-psql:hstore.sql:13: NOTICE: argument type hstore is only a shell
-psql:hstore.sql:132: NOTICE: type "ghstore" is not yet defined
-DETAIL: Creating a shell type definition.
-psql:hstore.sql:137: NOTICE: argument type ghstore is only a shell
+RESET client_min_messages;
+set escape_string_warning=off;
--hstore;
select ''::hstore;
hstore
@@ -483,50 +484,50 @@ select * from each('aaa=>bq, b=>NULL, ""=>1 ');
aaa | bq
(3 rows)
--- @
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL';
+-- @>
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL';
?column?
----------
t
(1 row)
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, c=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, c=>NULL';
?column?
----------
t
(1 row)
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, g=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, g=>NULL';
?column?
----------
f
(1 row)
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'g=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'g=>NULL';
?column?
----------
f
(1 row)
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
?column?
----------
f
(1 row)
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
?column?
----------
t
(1 row)
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>NULL';
?column?
----------
t
(1 row)
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>q';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>q';
?column?
----------
f
@@ -534,19 +535,19 @@ select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>q';
CREATE TABLE testhstore (h hstore);
\copy testhstore from 'data/hstore.data'
-select count(*) from testhstore where h @ 'wait=>NULL';
+select count(*) from testhstore where h @> 'wait=>NULL';
count
-------
189
(1 row)
-select count(*) from testhstore where h @ 'wait=>CC';
+select count(*) from testhstore where h @> 'wait=>CC';
count
-------
15
(1 row)
-select count(*) from testhstore where h @ 'wait=>CC, public=>t';
+select count(*) from testhstore where h @> 'wait=>CC, public=>t';
count
-------
2
@@ -554,19 +555,19 @@ select count(*) from testhstore where h @ 'wait=>CC, public=>t';
create index hidx on testhstore using gist(h);
set enable_seqscan=off;
-select count(*) from testhstore where h @ 'wait=>NULL';
+select count(*) from testhstore where h @> 'wait=>NULL';
count
-------
189
(1 row)
-select count(*) from testhstore where h @ 'wait=>CC';
+select count(*) from testhstore where h @> 'wait=>CC';
count
-------
15
(1 row)
-select count(*) from testhstore where h @ 'wait=>CC, public=>t';
+select count(*) from testhstore where h @> 'wait=>CC, public=>t';
count
-------
2
diff --git a/contrib/hstore/hstore.sql.in b/contrib/hstore/hstore.sql.in
index 98ca9cfbda..c77fc7d4fb 100644
--- a/contrib/hstore/hstore.sql.in
+++ b/contrib/hstore/hstore.sql.in
@@ -61,6 +61,30 @@ RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C' with (isstrict,iscachable);
+CREATE FUNCTION hs_contained(hstore,hstore)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' with (isstrict,iscachable);
+
+CREATE OPERATOR @> (
+ LEFTARG = hstore,
+ RIGHTARG = hstore,
+ PROCEDURE = hs_contains,
+ COMMUTATOR = '<@',
+ RESTRICT = contsel,
+ JOIN = contjoinsel
+);
+
+CREATE OPERATOR <@ (
+ LEFTARG = hstore,
+ RIGHTARG = hstore,
+ PROCEDURE = hs_contained,
+ COMMUTATOR = '@>',
+ RESTRICT = contsel,
+ JOIN = contjoinsel
+);
+
+-- obsolete:
CREATE OPERATOR @ (
LEFTARG = hstore,
RIGHTARG = hstore,
@@ -70,11 +94,6 @@ CREATE OPERATOR @ (
JOIN = contjoinsel
);
-CREATE FUNCTION hs_contained(hstore,hstore)
-RETURNS bool
-AS 'MODULE_PATHNAME'
-LANGUAGE 'C' with (isstrict,iscachable);
-
CREATE OPERATOR ~ (
LEFTARG = hstore,
RIGHTARG = hstore,
@@ -181,8 +200,10 @@ LANGUAGE 'C';
CREATE OPERATOR CLASS gist_hstore_ops
DEFAULT FOR TYPE hstore USING gist
AS
- OPERATOR 7 @ RECHECK,
- --OPERATOR 8 ~ RECHECK,
+ OPERATOR 7 @> RECHECK,
+ --OPERATOR 8 <@ RECHECK,
+ OPERATOR 13 @ RECHECK,
+ --OPERATOR 14 ~ RECHECK,
FUNCTION 1 ghstore_consistent (internal, internal, int4),
FUNCTION 2 ghstore_union (internal, internal),
FUNCTION 3 ghstore_compress (internal),
diff --git a/contrib/hstore/sql/hstore.sql b/contrib/hstore/sql/hstore.sql
index 298ffb0893..0931616077 100644
--- a/contrib/hstore/sql/hstore.sql
+++ b/contrib/hstore/sql/hstore.sql
@@ -1,7 +1,15 @@
+--
+-- first, define the datatype. Turn off echoing so that expected file
+-- does not depend on contents of hstore.sql.
+--
+SET client_min_messages = warning;
\set ECHO none
\i hstore.sql
-set escape_string_warning=off;
\set ECHO all
+RESET client_min_messages;
+
+set escape_string_warning=off;
+
--hstore;
select ''::hstore;
@@ -103,29 +111,29 @@ select * from svals('');
select * from each('aaa=>bq, b=>NULL, ""=>1 ');
--- @
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL';
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, c=>NULL';
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, g=>NULL';
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'g=>NULL';
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b';
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>NULL';
-select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>q';
+-- @>
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, c=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>NULL, g=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'g=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>NULL';
+select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>q';
CREATE TABLE testhstore (h hstore);
\copy testhstore from 'data/hstore.data'
-select count(*) from testhstore where h @ 'wait=>NULL';
-select count(*) from testhstore where h @ 'wait=>CC';
-select count(*) from testhstore where h @ 'wait=>CC, public=>t';
+select count(*) from testhstore where h @> 'wait=>NULL';
+select count(*) from testhstore where h @> 'wait=>CC';
+select count(*) from testhstore where h @> 'wait=>CC, public=>t';
create index hidx on testhstore using gist(h);
set enable_seqscan=off;
-select count(*) from testhstore where h @ 'wait=>NULL';
-select count(*) from testhstore where h @ 'wait=>CC';
-select count(*) from testhstore where h @ 'wait=>CC, public=>t';
+select count(*) from testhstore where h @> 'wait=>NULL';
+select count(*) from testhstore where h @> 'wait=>CC';
+select count(*) from testhstore where h @> 'wait=>CC, public=>t';
select count(*) from (select (each(h)).key from testhstore) as wow ;
select key, count(*) from (select (each(h)).key from testhstore) as wow group by key order by count desc, key;