Thread: [GENERAL] What is the problem with this query?
Hi, ALL, draft=# IF NOT EXISTS( SELECT 1 FROM pg_class c, pg_namespace n WHERE n.oid = c.relnamespace AND c.relname = 'abcattbl_tnam_ownr' AND n.nspname = 'public' ) THEN CREATE INDEX "abcattbl_tnam_ownr" ON "abcattbl"("abt_tnam" ASC, "abt_ownr" ASC); ERROR: syntax error at or near "IF" LINE 1: IF NOT EXISTS( SELECT 1 FROM pg_class c, pg_namespace n WHER... ^ Is "IF" operator not supported by PostgreSQL? Thank you.
On Sunday, July 23, 2017, Igor Korot <ikorot01@gmail.com> wrote:
Is "IF" operator not supported by PostgreSQL
IF is pl/pgsql, not SQL.
David J.
Hi, David, On Sun, Jul 23, 2017 at 5:07 PM, David G. Johnston <david.g.johnston@gmail.com> wrote: > On Sunday, July 23, 2017, Igor Korot <ikorot01@gmail.com> wrote: >> >> Is "IF" operator not supported by PostgreSQL So how do I write this properly? Thank you. > > > IF is pl/pgsql, not SQL. > > David J.
## Igor Korot (ikorot01@gmail.com): > >> Is "IF" operator not supported by PostgreSQL > So how do I write this properly? There is documentation for that: https://www.postgresql.org/docs/current/static/sql-createindex.html Regards, Christoph -- Spare Space
Hi, Christoph, On Sun, Jul 23, 2017 at 5:30 PM, Christoph Moench-Tegeder <cmt@burggraben.net> wrote: > ## Igor Korot (ikorot01@gmail.com): > >> >> Is "IF" operator not supported by PostgreSQL >> So how do I write this properly? > > There is documentation for that: > https://www.postgresql.org/docs/current/static/sql-createindex.html Except that IF NOT EXIST clause is introduced in 9.5. And if the server is <= 9.4? I tried to use a solution from here: https://dba.stackexchange.com/questions/35616/create-index-if-it-does-not-exist. but apparently I fail. Thank you. > > Regards, > Christoph > > -- > Spare Space > > > -- > Sent via pgsql-general mailing list (pgsql-general@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-general
On Sunday, July 23, 2017, Igor Korot <ikorot01@gmail.com> wrote:
Hi, David,
On Sun, Jul 23, 2017 at 5:07 PM, David G. Johnston
<david.g.johnston@gmail.com> wrote:
> On Sunday, July 23, 2017, Igor Korot <ikorot01@gmail.com> wrote:
>>
>> Is "IF" operator not supported by PostgreSQL
So how do I write this properly?
CREATE FUNCTION or a DO block. See docs for usage.
Since the language is pl/pgsql you can learn how to write it here.
David J.