store key name pattern search

Started by armand pirvuabout 9 years ago5 messagesgeneral
Jump to latest
#1armand pirvu
armand.pirvu@gmail.com

Hi

I have the following case

select * from foo;
col1
---------------------------------------------------------------------------------
"show_id"=>"1", "group_id"=>"32", "group_name"=>"slb", "group_add_by"=>"557651"
"show_id"=>"2", "group_id"=>"33", "group_name"=>"slc", "item_add_by"=>"557652"
(2 rows)

Is there anyway I can do a pattern search by hstore key name something like

select * from foo where skeys(col1) like '%add_by%';

I looked on the doc but did not see anything , or did I miss it ?

Thanks

Armand

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2Oleg Bartunov
oleg@sai.msu.su
In reply to: armand pirvu (#1)
Re: store key name pattern search

On Tue, Apr 4, 2017 at 11:41 AM, Armand Pirvu (home) <armand.pirvu@gmail.com

wrote:

Hi

I have the following case

select * from foo;
col1
------------------------------------------------------------
---------------------
"show_id"=>"1", "group_id"=>"32", "group_name"=>"slb",
"group_add_by"=>"557651"
"show_id"=>"2", "group_id"=>"33", "group_name"=>"slc",
"item_add_by"=>"557652"
(2 rows)

Is there anyway I can do a pattern search by hstore key name something like

select * from foo where skeys(col1) like '%add_by%';

I looked on the doc but did not see anything , or did I miss it ?

No. You may convert to json and use jsquery
https://github.com/postgrespro/jsquery

Show quoted text

Thanks

Armand

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3armand pirvu
armand.pirvu@gmail.com
In reply to: Oleg Bartunov (#2)
Re: store key name pattern search

Thank you

— Armand

On Apr 4, 2017, at 10:50 AM, Oleg Bartunov <obartunov@gmail.com> wrote:

Show quoted text

On Tue, Apr 4, 2017 at 11:41 AM, Armand Pirvu (home) <armand.pirvu@gmail.com> wrote:
Hi

I have the following case

select * from foo;
col1
---------------------------------------------------------------------------------
"show_id"=>"1", "group_id"=>"32", "group_name"=>"slb", "group_add_by"=>"557651"
"show_id"=>"2", "group_id"=>"33", "group_name"=>"slc", "item_add_by"=>"557652"
(2 rows)

Is there anyway I can do a pattern search by hstore key name something like

select * from foo where skeys(col1) like '%add_by%';

I looked on the doc but did not see anything , or did I miss it ?

No. You may convert to json and use jsquery
https://github.com/postgrespro/jsquery

Thanks

Armand

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Jeff Janes
jeff.janes@gmail.com
In reply to: armand pirvu (#1)
Re: store key name pattern search

On Tue, Apr 4, 2017 at 8:41 AM, Armand Pirvu (home) <armand.pirvu@gmail.com>
wrote:

Hi

I have the following case

select * from foo;
col1
------------------------------------------------------------
---------------------
"show_id"=>"1", "group_id"=>"32", "group_name"=>"slb",
"group_add_by"=>"557651"
"show_id"=>"2", "group_id"=>"33", "group_name"=>"slc",
"item_add_by"=>"557652"
(2 rows)

Is there anyway I can do a pattern search by hstore key name something like

select * from foo where skeys(col1) like '%add_by%';

I looked on the doc but did not see anything , or did I miss it ?

select * from foo where array_to_string(akeys(x),';') like '%add\_by%';

Note that I back-slashed the underscore, otherwise it acts as a wildcard
and may match more than you bargained for.

Cheers,

Jeff

#5armand pirvu
armand.pirvu@gmail.com
In reply to: Jeff Janes (#4)
Re: store key name pattern search

Thank you Jeff

Nice . I also looked at akeys/skeys

My goal is to get the key by pattern matching and then passing it back like in col1->key

Armand

On Apr 4, 2017, at 12:42 PM, Jeff Janes <jeff.janes@gmail.com> wrote:

Show quoted text

On Tue, Apr 4, 2017 at 8:41 AM, Armand Pirvu (home) <armand.pirvu@gmail.com> wrote:
Hi

I have the following case

select * from foo;
col1
---------------------------------------------------------------------------------
"show_id"=>"1", "group_id"=>"32", "group_name"=>"slb", "group_add_by"=>"557651"
"show_id"=>"2", "group_id"=>"33", "group_name"=>"slc", "item_add_by"=>"557652"
(2 rows)

Is there anyway I can do a pattern search by hstore key name something like

select * from foo where skeys(col1) like '%add_by%';

I looked on the doc but did not see anything , or did I miss it ?

select * from foo where array_to_string(akeys(x),';') like '%add\_by%';

Note that I back-slashed the underscore, otherwise it acts as a wildcard and may match more than you bargained for.

Cheers,

Jeff