Skip to content

Tag: postgresql

Join table with mapping of array in postgres

I want to join two table, with first table contain an array which is primary keys of second table in JSON format Answer demo:db<>fiddle You can use the ANY function: Edit: demo:db<>fiddle If you have jsonb arrays, you can use the @> operator. Note, that this works only if your integer id values…

How create Postgres database using SQLAlchemy

I want write project using database library (SQLAlchemy). When I use SQLite, all works good, but when I deploy project on server (Heroku with Postgres plugin), It doesn’t work. This is code for my database: I have engine & Base variable: In DATABASE_URL link to base on Heroku(Postgres). For create d…

Select all rows which match a condition dependent on over rows

Let’s assume I have a table T with the columns X, Y, Z where Z is some comparable value (I have to make it work on a PostgreSQL database but a solution that additionally supports oracle would be even nicer). What I want to achieve is best described by the following, sadly invalid query: This is invalid …

updating postgres table with unique Integer array

I am not so good in queries. I have a table with column users which is of type ‘users integer ARRAY’. For e.g. it looks like users[1,2] Now I want to update this array with new value, but it has to be distinct. For e.g. if I want to add 3 to it then the output should be users[1,2,3] and

Regexp search SQL query fields

I have a repository of SQL queries and I want to understand which queries use certain tables or fields. Let’s say I want to understand what queries use the email field, how can I write it? Example SQL …