Re: to pg

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Ramesh T <rameshparnanditech(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: to pg
Date: 2015-09-25 14:22:39
Message-ID: CAF-3MvP_8bXGk23tdsO36tYAWd7nZUV0LH9GGLOC5FxRM99GrQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Assuming that your queries are written in such a way that Oracle is
indeed using that index and you want your queries to use the index as
well in PG:

CREATE UNIQUE INDEX idx_load_pick ON (load_id) WHERE CASE picked WHEN
'y' THEN load_id ELSE NULL END IS NOT NULL;

That's definitely written a bit redundantly, that's Oracle's fault.

If your queries aren't like that, it's as Ladislav wrote. Much simpler in PG!

To make Oracle use your original index, your queries are probably of a
form containing snippets like:

SELECT *
FROM foo
WHERE CASE picked WHEN 'y' THEN load_id ELSE NULL END IS NOT NULL

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

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

In response to

  • to pg at 2015-09-25 11:08:44 from Ramesh T

Responses

  • Re: to pg at 2015-09-25 14:44:09 from Tom Lane

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Reyes 2015-09-25 14:22:52 Re: Dropped connections with pg_basebackup
Previous Message Francisco Reyes 2015-09-25 14:20:44 Re: Dropped connections with pg_basebackup