Home > database >  What does this part of my SQL query mean?
What does this part of my SQL query mean?

Time:01-19

sum( (record_id is NULL AND joined.table_id is NULL)::int ) I know the sum returns the sum of the column entries, but what will this expression (... and...) return, can it be compared with this expression (.. ..), and what does this ()::int?? convert result to int?

i dont know will return this expression, on my sampling will returned number of integer

CodePudding user response:

It is a more complicated way to write

count(*) FILTER (WHERE record_id IS NULL
                   AND joined.table_id IS NULL)

CodePudding user response:

(record_id is NULL AND joined.table_id is NULL)::int will return 1 iff both record_id and joined.table_id are null.

Therefore, sum( (record_id is NULL AND joined.table_id is NULL)::int ) will return the number of rows in which both record_id and joined.table_id are null.

  • Related