Re: IF NOT EXIST

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: IF NOT EXIST
Дата
Msg-id 27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com
обсуждение исходный текст
Ответ на IF NOT EXIST  (Igor Korot <ikorot01@gmail.com>)
Ответы Re: IF NOT EXIST
Список pgsql-general
> On 18 Dec 2018, at 7:10, Igor Korot <ikorot01@gmail.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
optionsand 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.
You will also have to specify a return type (functions return values) and the language the function is implemented in.
Thedocumentation 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.


В списке pgsql-general по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: Format an Update with calculation
Следующее
От: Laurenz Albe
Дата:
Сообщение: Re: How to insert bulk data with libpq in C?