question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Querying HSTORE in postgres

See original GitHub issue

I have a model that has an HSTORE column. I would like to use Sequelize’s find method to perform queries searching for records based on data in the HSTORE column.

The raw query is:

SELECT row_data
FROM audit.logged_action AS logged_action 
WHERE logged_action.action = 'I'
AND row_data ? 'id'
AND row_data->'id' = '16'

My (failed) attempt in Sequelize:

LoggedAction.findOne({
  where: {
     action: 'I',
     row_data: {
       id: billingDetail.id
     }
   }
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
legomindcommented, Nov 19, 2016

@janmeier I am considering creating a PR for this. Would the following be correct?

Current Functionality

User.findOne({
  where: {
    hstore_field: {
      fieldOne: 'some_value',
    },
  },
});

would produce

SELECT *
FROM Users
WHERE hstore_field = '"fieldOne" => "some_value"'

New functionality

User.findOne({
  where: {
    hstore_field: {
      $contains: {
        fieldOne: 'some_value',
      },
    },
  },
});

would produce

SELECT *
FROM Users
WHERE hstore_field -> 'fieldOne' = 'some_value'
0reactions
stale[bot]commented, Jun 29, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL hstore Tutorial
You can query the rows whose hstore column contain multiple keys using ?& operator. For example, you can get books where attr column...
Read more >
Documentation: 15: F.18. hstore - PostgreSQL
This module implements the hstore data type for storing sets of key/value pairs within a single PostgreSQL value. This can be useful in...
Read more >
How to query values with wildcards in PostgreSQL hstore
You can extract values by key from an hstore column with the -> operator. SELECT data->'Supplier' AS sup FROM products WHERE ...
Read more >
PostgreSQL hstore - Javatpoint
PostgreSQL hstore data type allows us to use the -> operator to select a particular key's data values from an hstore column (Movie_Attr)....
Read more >
How hstore data Type works in PostgreSQL? - eduCBA
The PostgreSQL hstore column works dynamically, which means you do not need to specify the key prior to the table creation; you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found