Thread: SQL Question
I'm trying to do some type of conditional select statement and I have no idea how. What I would like is something like this (using pseudo sql) select (if(col1>1) true else if (col1<= 1) false) from foo; does that make sense? Basically I want one column of my result set to be true or false based on some logic. I can do it in code and have my program handle it, but I was hoping to do it in SQL. Thanks, Matt O'Connor
Matthew <matt@ctlno.com> writes: > What I would like is something like this (using pseudo sql) > select (if(col1>1) true else if (col1<= 1) false) from foo; This particular example could be written as just select col1>1 from foo since a boolean result is a perfectly good result. More generally, you could use the CASE construct for conditional expressions. See http://www.postgresql.org/devel-corner/docs/postgres/functions-conditional.html regards, tom lane