skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  2. It is a more complicated way to write

    count(*) FILTER (WHERE record_id IS NULL
                       AND joined.table_id IS NULL)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search