Skip to content

Instantly share code, notes, and snippets.

Created June 6, 2012 15:31
Show Gist options
  • Save anonymous/2882667 to your computer and use it in GitHub Desktop.
Save anonymous/2882667 to your computer and use it in GitHub Desktop.
HSTORE exist function

exist function

The second parameter of exist has to be an string, and the quote has to be escaped as ''.

For example, where not exist(data, '''a''')

Full example

example_db=# create table something (id serial primary key, data hstore);
CREATE TABLE
example_db=# insert into something (data) values ('''a'' => 1');
INSERT 0 1
example_db=# insert into something (data) values ('''a'' => 2');
INSERT 0 1
example_db=# insert into something (data) values ('''b'' => 2');
INSERT 0 1

example_db=# select * from something;
 id |    data    
----+------------
  1 | "'a'"=>"1"
  2 | "'a'"=>"2"
  3 | "'b'"=>"2"
(3 filas)

example_db=# select * from something where not exist(data, '''a''');
 id |    data    
----+------------
  3 | "'b'"=>"2"
(1 fila)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment