Vitaly Litvinov
Vitaly Litvinov

Reputation: 29

What does this part of my SQL query mean?

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

Upvotes: 1

Views: 43

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 246568

It is a more complicated way to write

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

Upvotes: 4

ntm
ntm

Reputation: 741

(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.

Upvotes: 1

Related Questions