Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r2Cqn-00FU5J-CH for pgsql-general@arkaria.postgresql.org; Sun, 12 Nov 2023 15:58:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r2Cqm-00AwzJ-0o for pgsql-general@arkaria.postgresql.org; Sun, 12 Nov 2023 15:58:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r2Cql-00AwzB-MD for pgsql-general@lists.postgresql.org; Sun, 12 Nov 2023 15:58:15 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r2Cqj-005ELK-8N for pgsql-general@lists.postgresql.org; Sun, 12 Nov 2023 15:58:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3ACFw93H1741397; Sun, 12 Nov 2023 10:58:09 -0500 From: Tom Lane To: Ron cc: Thiemo Kellner , pgsql-general@lists.postgresql.org Subject: Re: Conditional compilation In-reply-to: <8e2dca7c-e73d-41c7-83d1-28e5b414eaf1@gmail.com> References: <1ed285e8-2ac0-4873-87e9-02a4d412732d@gelassene-pferde.biz> <8e2dca7c-e73d-41c7-83d1-28e5b414eaf1@gmail.com> Comments: In-reply-to Ron message dated "Sun, 12 Nov 2023 09:37:47 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1741395.1699804689.1@sss.pgh.pa.us> Date: Sun, 12 Nov 2023 10:58:09 -0500 Message-ID: <1741396.1699804689@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ron writes: > On 11/12/23 09:32, Thiemo Kellner wrote: >> Does PostgreSQL have something like Oracle's conditional compilation? This >> is sort of an if then statement that gets evaluated on >> compilation/installation time of PL/SQL code. If the condition is met, the >> code until the $END gets compiled. It is even possible to switch on/off >> parts of single statements. I suppose it is sort of a preprocessor that >> removes the code part from $IF until $END if the condition is not met. > Pl/PgSQL is an interpreted language; there is no compilation. At > creation/installation, it just (I think) does syntax checks; it definitely > doesn't care if a table exists or not. Yeah. You can get at least some of the effect of this by just writing if-statements. The non-executed chunks of code still have to be grammatically valid SQL, but they don't ever reach parse analysis so nothing happens beyond minimal syntax checking. If that's not enough, what you'll want to look at is using EXECUTE to execute dynamically-constructed SQL. regards, tom lane