Hi

Ășt 18. 12. 2018 v 7:11 odesĂ­latel Igor Korot <ikoro...@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.
>
>

Reply via email to