mirror of
https://github.com/postgres/postgres.git
synced 2026-01-05 23:38:41 +03:00
Rename contrib contains/contained-by operators to @> and <@, per discussion.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user