Re: IF NOT EXIST

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: IF NOT EXIST
Дата
Msg-id CAFj8pRBAYy1C1oCRpm=U=t-Z6LyuvJH27M3SytOC9QX4gWH_7w@mail.gmail.com
обсуждение исходный текст
Ответ на IF NOT EXIST  (Igor Korot <ikorot01@gmail.com>)
Список pgsql-general
Hi

út 18. 12. 2018 v 7:11 odesílatel Igor Korot <ikorot01@gmail.com> napsal:
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?

IF is only plpgsql statement - so you cannot to call it from SQL environment.

CREATE FUNCTION is not expensive command, and you can replace existing function by statement

CREATE OR REPLACE FUNCTION ...

This is usual solution. You cannot to use in SQL IF statement ever in PostgreSQL - This T-SQL syntax is not supported.

But lot of DDL statements has integrated IF

DROP TABLE IF EXISTS ...
CREATE TABLE IF NOT EXISTS ...
CREATE OR REPLACE FUNCTION ...

second solution is using SQL command DO - inside is plpgsql code, and you can use conditional statement like IF, or other.

regards

Pavel

Thank you.

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

Предыдущее
От: Igor Korot
Дата:
Сообщение: IF NOT EXIST
Следующее
От: Bret Stern
Дата:
Сообщение: Format an Update with calculation