0

I know from using Oracle that conditonal index with CASE statement is possible. But is it possible in PostgreSQL? For example index is following:

CREATE INDEX IX_INDEXNAME ON SOME_TABLE (
     CASE 
        WHEN COLUMN1 = 0 AND COLUMN2 = 'value' THEN SOME1_ID
        ELSE SOME2_ID
     END);

This is already modified version for PostgreSQL, because Oracle case statement is different from Postgres. If this is possbile how do I do that? Or if this is not possible, is there another way to realize it?

4
  • Yes this is possible. What is your question? Commented Jan 19, 2015 at 19:28
  • If this is possible, how do I do that? :) Commented Jan 19, 2015 at 19:29
  • Doesn't the create index work that you have? If not, was is the error? Commented Jan 19, 2015 at 19:29
  • [42601] ERROR: syntax error at or near "CASE" Commented Jan 19, 2015 at 19:31

1 Answer 1

2

You need to enclose the CASE expression in parentheses:

CREATE INDEX IX_INDEXNAME ON SOME_TABLE (
     (CASE 
        WHEN COLUMN1 = 0 AND COLUMN2 = 'value' THEN SOME1_ID
        ELSE SOME2_ID
     END) );
Sign up to request clarification or add additional context in comments.

Comments

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.