3

Instead of stating each column name individually, is there a more efficient way to select all rows which do not have any nulls from a table in a Postgres database?

For example, if there are 20 columns in a table, how to avoid typing out each of those columns individually?

1 Answer 1

9

Just check the whole row:

select *
from my_table
where my_table is not null

my_table is not null is only true if all columns in that rows are not null.

Sign up to request clarification or add additional context in comments.

5 Comments

How would you select tables with joins?
@ShayHa: the same way.
sql select * from my_table inner join my_other_table where my_table is not null Like that?
Cool, where is this in the postgres documentation? What is this called? Can you apply expressions to whole tables in general, and the results for each column get ANDed together?
In terms of performance, is it better than checking all columns with different queries? Will the cursor parse the whole table or is there some sort of indexation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.