Is it possible to name the output column created with case
("switch") in a PostgreSQL SELECT
statement? It appears from the documentation that this is not possible. An example usage of what I would like to do is:
SELECT CASE (column) WHEN 1 THEN 'One' END AS 'TheColumn' FROM TABLE ;
It works for me (pg-9.1)
CREATE TABLE one
( one INTEGER
);
INSERT INTO one(one) values ( 0), (1), (NULL);
SELECT case one
when 1 then 'one'
when 0 then 'zero'
else 'other'
end AS the_one
FROM one;
So, the single quotes (that you used to quote the aliased column name) should have been double quotes (or absent).
The result:
CREATE TABLE
INSERT 0 3
UPDATE 3
the_one
---------
one
zero
other
(3 rows)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With