Cruclax
Cruclax

Reputation: 414

Postgres / hstore : how to get IDs of rows with certain key in their hstore field?

I'm querying a pgsql DB to find rows that have certain keys in an hstore field:

select DISTINCT
from (select id, exist(data, ‘exercise_quiz’) key_exists
  from user_tracking) x
where key_exists = true;

It works fine, but I need to print the IDs of the corresponding rows it returns. Can I do this with this command?

Upvotes: 2

Views: 258

Answers (1)

klin
klin

Reputation: 121594

Use the operator hstore ? text (does hstore contain key?):

select id
from user_tracking
where data ? 'exercise_quiz';

Upvotes: 2

Related Questions