Re: IF NOT EXIST

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Alban Hertroys <haramrae(at)gmail(dot)com>, Igor Korot <ikorot01(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: IF NOT EXIST
Date: 2018-12-18 13:53:21
Message-ID: 30b9e725-dc1e-fbe3-7011-69799bb297b7@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/18/18 12:02 AM, Alban Hertroys wrote:
>
>> On 18 Dec 2018, at 7:10, Igor Korot <ikorot01(at)gmail(dot)com> wrote:
>>
>> Hi, ALL,
>> I have a following statement:
>>
>> IF NOT EXIST( SELECT 1 SELECT 1 FROM pg_proc AS proc, pg_namespace AS
>> ns ) CREATE FUNCTION();
>>
>> Unfortunately trying to execute it thru the ODBC interface with:
>>
>> ret = SQLExecDirect( m_hstmt, query, SQL_NTS );
>>
>> gives syntax error near IF.
>>
>> What is the proper way to do that?
>
> It looks like you’re trying to create a function unless it already exists, but you’re missing several important parts.
>
> Firstly, the statement you’re looking for is CREATE OR REPLACE FUNCTION. Look it up in the docs for the various syntax options and for how to use it, as…
>
> Secondly, your function doesn’t have a name. A function requires a name, or you wouldn’t ever be able to call it.

With an exception:

https://www.postgresql.org/docs/10/sql-do.html

> You will also have to specify a return type (functions return values) and the language the function is implemented in. The documentation will show you that there are several options you can provide too.
>
> And lastly, a function requires an implementation.
>
> Regards,
>
> Alban Hertroys
> --
> There is always an exception to always.
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bret Stern 2018-12-18 15:51:13 Re: Format an Update with calculation
Previous Message Adrian Klaver 2018-12-18 13:51:16 Re: Format an Update with calculation