Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZAKk-0005jB-9t for pgsql-general@arkaria.postgresql.org; Tue, 18 Dec 2018 08:02:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZAKj-0006W4-1r for pgsql-general@arkaria.postgresql.org; Tue, 18 Dec 2018 08:02:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZAKi-0006Vx-Ma for pgsql-general@lists.postgresql.org; Tue, 18 Dec 2018 08:02:28 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZAKg-0005eQ-65 for pgsql-general@postgresql.org; Tue, 18 Dec 2018 08:02:27 +0000 Received: by mail-ed1-x52b.google.com with SMTP id f9so13025816eds.10 for ; Tue, 18 Dec 2018 00:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=QJJcXG3SzfjJbOteWs8MmXX1sgob8hCtXAFC/uIFV3A=; b=NpLEOJe0+B0rp5V/rLRBIlPHTviNkWaXZUao7zmv5BX5zTsLUUEGhORo0Ocujkbsqx N7vozSh2eik6c7h8LTCa3bWABJe5tC3S7acRI6HDvEtuUoX9ysxHWkhaOC/8c8yH5rml ydRg+pdjVH2ywfEYlhwR8O7F210uz8UfJZuNLSJWR+KV1/K7kbN6jF6MoxO/w37PK5pf 8dwrrR0seB2WQSSr/O5kOSvyhqa3IpOAxuU/ZfgKkBGfEd2iOhHg6zCpzgV2QXPsIYiO zBhx8WPHNoR3VJHXepYRdbUyyuw7btgCJmKuH6lnPoiEstONIvxexBSvCKb4ZaSJy8Pd ZyRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=QJJcXG3SzfjJbOteWs8MmXX1sgob8hCtXAFC/uIFV3A=; b=cep/fMnd6Ai4MzTslWOjVuxRJQF9WAtpCQbO0ac9cAsvQ+QpPsdC3t9mC4gi2Ive2B 38q6ZcRIGwN04jw+PAfWKsybNgvB26RkAtU5/pOf94DLaDPJKaPGiimB6z236PrihDmg 9npZSxtedD41BBd+Nn0Ai/pA9xBVM7qr/gI8AUEQBx6I4tEuXzf4b91U6dojgZSiu/yi trIWfCPxucxmB3yQAyVzkRVmDQlN5cNgexsjRwhY0GFmTR40R1aism9fwHjh9up2BZma a9RGpaUqHZOVRQrlGPCVmPD0I2jYov9KDcdGIvwp8RFSEyPHwjj+4qsPFBtOPXbb60FX d/2Q== X-Gm-Message-State: AA+aEWbBRPEQKT6OT5CRrMoXxdTeMSoVN8dSBj86nhi9Wicv3uLvPIFA lpSRUkDmElFRg/V1XNQfJj0= X-Google-Smtp-Source: AFSGD/XPAGX5SJpCJR1GWG6WiWAGlFzLWpJzBwifH+H6HTkIOTUiYQA1z+Y/0Jxv4F63+HnKY9b3Mw== X-Received: by 2002:a17:906:1d5:: with SMTP id 21-v6mr6477900ejj.206.1545120143998; Tue, 18 Dec 2018 00:02:23 -0800 (PST) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id n16-v6sm2105082eja.6.2018.12.18.00.02.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 00:02:23 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: IF NOT EXIST From: Alban Hertroys In-Reply-To: Date: Tue, 18 Dec 2018 09:02:21 +0100 Cc: pgsql-general Content-Transfer-Encoding: quoted-printable Message-Id: <27AD9468-60E6-4D36-9026-49A385B0CC6C@gmail.com> References: To: Igor Korot X-Mailer: Apple Mail (2.3445.102.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 18 Dec 2018, at 7:10, Igor Korot wrote: >=20 > Hi, ALL, > I have a following statement: >=20 > IF NOT EXIST( SELECT 1 SELECT 1 FROM pg_proc AS proc, pg_namespace AS > ns ) CREATE FUNCTION(); >=20 > Unfortunately trying to execute it thru the ODBC interface with: >=20 > ret =3D SQLExecDirect( m_hstmt, query, SQL_NTS ); >=20 > gives syntax error near IF. >=20 > What is the proper way to do that? It looks like you=E2=80=99re trying to create a function unless it = already exists, but you=E2=80=99re missing several important parts. Firstly, the statement you=E2=80=99re 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=E2=80=A6 Secondly, your function doesn=E2=80=99t have a name. A function requires = a name, or you wouldn=E2=80=99t 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.