Re: to pg

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: Ramesh T <rameshparnanditech(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: to pg
Date: 2015-09-25 14:44:09
Message-ID: 4824.1443192249@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alban Hertroys <haramrae(at)gmail(dot)com> writes:
> On 25 September 2015 at 13:08, Ramesh T <rameshparnanditech(at)gmail(dot)com> wrote:
>> CREATE UNIQUE INDEX idx_load_pick ON pick (case picked when picked='y' then
>> load_id else null end );
>>
>> how can i convert case expressed to postgres..above it is oracle.

> BTW, your CASE statement isn't exactly valid, even in Oracle. Your
> comparison is in fact this: picked = picked='y'.

Yeah. Aside from that confusion, the other reason this command doesn't
work as-is is you need more parentheses. An expression in an index has
to either look like a function call or be parenthesized. So:

regression=# create table pick (picked text, load_id int);
CREATE TABLE
regression=# CREATE UNIQUE INDEX idx_load_pick ON pick (case picked when picked='y' then load_id else null end );
ERROR: syntax error at or near "case"
regression=# CREATE UNIQUE INDEX idx_load_pick ON pick ((case picked when picked='y' then load_id else null end ));
ERROR: operator does not exist: text = boolean
regression=# CREATE UNIQUE INDEX idx_load_pick ON pick ((case when picked='y' then load_id else null end ));
CREATE INDEX

regards, tom lane

In response to

  • Re: to pg at 2015-09-25 14:22:39 from Alban Hertroys

Browse pgsql-general by date

  From Date Subject
Next Message yuryu 2015-09-25 15:20:00 Test failover for PosgreSql 9.2
Previous Message Francisco Reyes 2015-09-25 14:22:52 Re: Dropped connections with pg_basebackup