pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14704: How to create unique index with a case statement?
3+ messages / 2 participants
[nested] [flat]
* BUG #14704: How to create unique index with a case statement?
@ 2017-06-13 05:24 naveen7eceindia@gmail.com
0 siblings, 1 reply; 3+ messages in thread
From: naveen7eceindia@gmail.com @ 2017-06-13 05:24 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14704
Logged by: Naveen Vemula
Email address: naveen7eceindia@gmail.com
PostgreSQL version: 9.6.0
Operating system: Windows
Description:
CREATE UNIQUE INDEX XAK2TRADPAADR_TD ON TRADPAADR_TD(TPID,
case TDADRTYP when 'BY' then 0
else TDID
end,
case TDADRNO when '1' then 0
else TDID
end,
case TDLANG when 'ENG' then 0
else 1
end);
ERROR: syntax error at or near "case"
LINE 4: case TDADRTYP
^
********** Error **********
ERROR: syntax error at or near "case"
SQL state: 42601
Character: 72
Here TDADRTYP - varchar(4)
TDID - bigint
TDADRNO - varchar(15)
TDLANG - varchar(4)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #14704: How to create unique index with a case statement?
@ 2017-06-13 06:18 Pantelis Theodosiou <ypercube@gmail.com>
parent: naveen7eceindia@gmail.com
0 siblings, 1 reply; 3+ messages in thread
From: Pantelis Theodosiou @ 2017-06-13 06:18 UTC (permalink / raw)
To: naveen7eceindia@gmail.com; +Cc: pgsql-bugs
On Tue, Jun 13, 2017 at 6:24 AM, <naveen7eceindia@gmail.com> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14704
> Logged by: Naveen Vemula
> Email address: naveen7eceindia@gmail.com
> PostgreSQL version: 9.6.0
> Operating system: Windows
> Description:
>
> CREATE UNIQUE INDEX XAK2TRADPAADR_TD ON TRADPAADR_TD(TPID,
> case TDADRTYP when 'BY' then 0
> else TDID
> end,
> case TDADRNO when '1' then 0
> else TDID
> end,
> case TDLANG when 'ENG' then 0
> else 1
> end);
>
> ERROR: syntax error at or near "case"
> LINE 4: case TDADRTYP
> ^
> ********** Error **********
>
> ERROR: syntax error at or near "case"
> SQL state: 42601
> Character: 72
>
> Here TDADRTYP - varchar(4)
> TDID - bigint
> TDADRNO - varchar(15)
> TDLANG - varchar(4)
>
>
>
> You need to put each CASE expression inside parentheses:
CREATE UNIQUE INDEX XAK2TRADPAADR_TD ON TRADPAADR_TD
( TPID,
(case TDADRTYP when 'BY' then 0 else TDID end),
(case TDADRNO when '1' then 0 else TDID end),
(case TDLANG when 'ENG' then 0 else 1 end)
) ;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #14704: How to create unique index with a case statement?
@ 2017-06-13 06:19 Pantelis Theodosiou <ypercube@gmail.com>
parent: Pantelis Theodosiou <ypercube@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Pantelis Theodosiou @ 2017-06-13 06:19 UTC (permalink / raw)
To: naveen7eceindia@gmail.com; +Cc: pgsql-bugs
On Tue, Jun 13, 2017 at 7:18 AM, Pantelis Theodosiou <ypercube@gmail.com>
wrote:
>
>
> On Tue, Jun 13, 2017 at 6:24 AM, <naveen7eceindia@gmail.com> wrote:
>
>> The following bug has been logged on the website:
>>
>> Bug reference: 14704
>> Logged by: Naveen Vemula
>> Email address: naveen7eceindia@gmail.com
>> PostgreSQL version: 9.6.0
>> Operating system: Windows
>> Description:
>>
>> CREATE UNIQUE INDEX XAK2TRADPAADR_TD ON TRADPAADR_TD(TPID,
>> case TDADRTYP when 'BY' then 0
>> else TDID
>> end,
>> case TDADRNO when '1' then 0
>> else TDID
>> end,
>> case TDLANG when 'ENG' then 0
>> else 1
>> end);
>>
>> ERROR: syntax error at or near "case"
>> LINE 4: case TDADRTYP
>> ^
>> ********** Error **********
>>
>> ERROR: syntax error at or near "case"
>> SQL state: 42601
>> Character: 72
>>
>> Here TDADRTYP - varchar(4)
>> TDID - bigint
>> TDADRNO - varchar(15)
>> TDLANG - varchar(4)
>>
>>
>>
>> You need to put each CASE expression inside parentheses:
>
> CREATE UNIQUE INDEX XAK2TRADPAADR_TD ON TRADPAADR_TD
> ( TPID,
> (case TDADRTYP when 'BY' then 0 else TDID end),
> (case TDADRNO when '1' then 0 else TDID end),
> (case TDLANG when 'ENG' then 0 else 1 end)
> ) ;
>
>
As the docs state in CREATE INDEX
https://www.postgresql.org/docs/current/static/sql-createindex.html :
> The key field(s) for the index are specified as column names, or
alternatively as expressions written in parentheses.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2017-06-13 06:19 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-06-13 05:24 BUG #14704: How to create unique index with a case statement? naveen7eceindia@gmail.com
2017-06-13 06:18 ` Pantelis Theodosiou <ypercube@gmail.com>
2017-06-13 06:19 ` Pantelis Theodosiou <ypercube@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox