An answer elsewhere on SO provides the Postgresql NOT(<table> IS NOT NULL) query as an option to find all rows in a table containing one or more null values. How would one apply this query in the Django ORM without writing raw SQL? Or is this a case where raw SQL is required? I couldn’t find an ex…
Tag: postgresql
Insertion by removing ‘000000’ in the unix timestamp
I’m inserting some data for python that comes from a GET in API FLASK like JSON, for some reason when python will insert this data or maybe postgres itself, it is removing the 000000 Data json: Insert py: Original date: Date that python is inserting to pgsql: Conversion correct: Even using the website&#…
Return only one row in subquery
I have the following query that I’m executing to show these records on a Laravel view. I’m having issues with this line Because there are a lot of cities with the same name in my database, so it’s throwing an error, (probably the same with states but the error is being thrown at cities in th…
Fixing set-returning functions are not allowed in UPDATE
After upgrading to Postgres 12 statement throws error set-returning functions are not allowed in UPDATE How to fix this ? In Postgres 9.1 it worked. I read similar answers here but they recomment to totally overwrite statement. Maybe there is simply change which makes this statement work ? Result should by an…
In PostgreSQL, how to query for a computed results by the grouping of a field?
In my PostgreSQL database I have an invitations table like so: Invitations Table: Fields Details I’d like to query the Invitations table and group by unique sources. And then per source, include the total # of records and the total of those completed. Completed being where complated_at is NOT NULL. Desi…
convert column in rows and get count of different values of same column in postresql
test convert column in rows and get count of different values of same column in postresql
How to make left join with `where second_table.key!=’value’` if there is not record in secord_table at all
There are two tables with one-to-one relationship, and it’s a legal that the second table can have less rows than the first. Here is a sql code with inserted data: I need to make a query for all data + data_extra tables where extra!=’e1′ Here is my try: The problem with this query, that it d…
Matching literal percent in h2/postgres?
I have the following value in a db column: some%thing I’m using h2 and postgres, but can’t figure out why this query, where I have escaped the % to perform a literal search, is not matching the row …
how can i get the sum of two colums realtime
i have the following I want to have something like that select *, a+b as mes from maths; but to have a column sum and evrytime the columns a and b get update calculate the new sum in columns sum i try this and i get the following error Answer The syntax for generated column in PostgreSQL is: Demo: https://dbf…
Simple Postgres query returning no result
I have two tables: and I have indexes on id in both tables, and an index on website_id and product_id on the adjustments table. This query returns data but it takes some 5 seconds with some 1k products and a couple hundred in adjustments: This other query however returns no results when there’s nothing …