Reputation: 321
I'm trying to follow the instructions in the PostgreSQL manual. PostgreSQL: Documentation: 9.1: Control Structures My PostgreSQL server is version 9.1.14 on Windows 32-bit.
The following SQL statement is unexpectedly resulting in a syntax error:
SELECT
CASE 1
WHEN 1,2 THEN 'x'
ELSE 'y'
END;
I'm expecting it to return 'x';
The more traditional code runs fine, however:
SELECT
CASE 1
WHEN 1 THEN 'x'
WHEN 2 THEN 'x'
ELSE 'y'
END;
Upvotes: 2
Views: 5673
Reputation: 66243
You are using the CASE
syntax as provided by the procedural language plpgsql
. This is similar but not identical to the SQL CASE
syntax. Here is the link to the SQL version of CASE
.
Here you see, that 1,2
is not allowed, only a plain expression
. So you could write:
SELECT
CASE
WHEN 1 in (1,2) THEN 'x'
ELSE 'y'
END;
Upvotes: 4