Postgresql, select empty fields

后端 未结 1 896
闹比i
闹比i 2021-01-03 23:27

I\'m trying to get empty \"text\" fields from my table which I cleared manually with pgadmin. Initially in those fields was \'\' and I can query them like this:



        
1条回答
  •  盖世英雄少女心
    2021-01-03 23:39

    SELECT mystr, mystr1 
    FROM mytable 
    WHERE COALESCE(mystr, '') = '' 
       OR COALESCE(mystr1, '') = ''
        ;
    

    Explanation: the coalesce(a,b,c, ...) function traverses the list a,b,c,... from left to right and stops at the first non-null element. a,b,c can be any expression (or constant), but must yield the same type (or be coercable to the same type).

    0 讨论(0)
提交回复
热议问题