2

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;

1 Answer 1

4

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;
Sign up to request clarification or add additional context in comments.

1 Comment

I tested plpgsql before posting, by moving my select statement into a function. ;) I see how this works now. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.