pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alban Hertroys <haramrae@gmail.com>
To: Igor Korot <ikorot01@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: IF NOT EXIST
Date: Tue, 18 Dec 2018 09:02:21 +0100
Message-ID: <27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com> (raw)
In-Reply-To: <CA+FnnTyg6BZ0u+CCddbJLZoHF3HHSEvEt1xvWHF3b+jqPduEhg@mail.gmail.com>
References: <CA+FnnTyg6BZ0u+CCddbJLZoHF3HHSEvEt1xvWHF3b+jqPduEhg@mail.gmail.com>


> 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 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.
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.




view thread (4+ messages)  latest in thread

Message-ID: <27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com>
Permalink:  ../27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com/
Also on:    postgresql.org/message-id/27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: haramrae@gmail.com, ikorot01@gmail.com
  Subject: Re: IF NOT EXIST
  In-Reply-To: <27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com>
  References: <CA+FnnTyg6BZ0u+CCddbJLZoHF3HHSEvEt1xvWHF3b+jqPduEhg@mail.gmail.com> <27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox