SELECT * FROM table WHERE NOT (table IS NOT NULL);
finds all the rows in table
that have a null
value in any column. The logic is clear (see answer), but want to understand this syntax. A statement in an answer says "the reference to the table (alias) refers to an existing row" and the PostgreSQL SELECT
documentation’s WHERE
section states that "a row satisfies the condition if it returns true when the actual row values are substituted for any variable references" (emphasis mine). A keyword search on "row values" yielded references to the 4.2 Value Expressions page, but I couldn’t find an answer there either (unless I overlooked something).
2
Answers
A variation on the answer from here could be (all of the code below is available on the fiddle here):
Now, it uses a regex and these can be expensive – as we can see from the `EXPLAIN (ANALYZE, VERBOSE, BUFFERS, SETTINGS) <My_Query>’ – my regex query is about 3 times as expensive as
I also included a couple of other variants of using the
ROW
keyword in the fiddle.The technical term in PostgreSQL is a “whole-row reference”, and it doesn’t seem to be documented except in the source code. By using the table name as a column, you get a composite value consisting of all columns.
You can see
as being the same as