Skip to content

Tag: postgresql

Check whether value exists in column for each group

Having a difficult time putting what I am trying to do into words so searching is also difficult. Basically I am trying to look whether a certain value exists in a column, partitioned by group, and then propagate that value forward. In this example I want to check whether a user has completed the tutorial and…

PostgreSQL, SELECT CASE COALESCE

I need to ‘name’ categories: mycat is a text column with possible values ‘0’ to ‘4’. That works OK, but I have some an error in my program which very rarely writes null (or ” as I can see in pgAdmin). In such cases I have to treat that ” the same as ‘0&#82…

Return 1 if number exists in table and 0 otherwise

I want to return 1 if some number already exists in table and 0 otherwise. I tried something but it doesn’t work: I want something similar to exists function that already exists in PostgreSQL, but instead of true and false I want 1 or 0. Answer EXISTS yields a boolean result. The simple way to achieve w…