pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedConditional compilation
4+ messages / 3 participants
[nested] [flat]
* Conditional compilation
@ 2023-11-12 15:32 Thiemo Kellner <thiemo@gelassene-pferde.biz>
2023-11-12 15:37 ` Re: Conditional compilation Ron <ronljohnsonjr@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Thiemo Kellner @ 2023-11-12 15:32 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Hi
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.
Kind regards
Thiemo
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Conditional compilation
2023-11-12 15:32 Conditional compilation Thiemo Kellner <thiemo@gelassene-pferde.biz>
@ 2023-11-12 15:37 ` Ron <ronljohnsonjr@gmail.com>
2023-11-12 15:58 ` Re: Conditional compilation Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Ron @ 2023-11-12 15:37 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 11/12/23 09:32, Thiemo Kellner wrote:
> Hi
>
> 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.
--
Born in Arizona, moved to Babylonia.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Conditional compilation
2023-11-12 15:32 Conditional compilation Thiemo Kellner <thiemo@gelassene-pferde.biz>
2023-11-12 15:37 ` Re: Conditional compilation Ron <ronljohnsonjr@gmail.com>
@ 2023-11-12 15:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-11-12 16:47 ` Re: Conditional compilation Thiemo Kellner <thiemo@gelassene-pferde.biz>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2023-11-12 15:58 UTC (permalink / raw)
To: Ron <ronljohnsonjr@gmail.com>; +Cc: Thiemo Kellner <thiemo@gelassene-pferde.biz>; pgsql-general@lists.postgresql.org
Ron <ronljohnsonjr@gmail.com> 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Conditional compilation
2023-11-12 15:32 Conditional compilation Thiemo Kellner <thiemo@gelassene-pferde.biz>
2023-11-12 15:37 ` Re: Conditional compilation Ron <ronljohnsonjr@gmail.com>
2023-11-12 15:58 ` Re: Conditional compilation Tom Lane <tgl@sss.pgh.pa.us>
@ 2023-11-12 16:47 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
0 siblings, 0 replies; 4+ messages in thread
From: Thiemo Kellner @ 2023-11-12 16:47 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Thanks for pointing out. The only use case of conditional compilation, I
can think of, is, that one can have arbitrary logging code in some
environments without performance penalty in others, e.g. log as hell in
dev, no logging at all in prod without the "function" having to execute
checks for every and each logging statement put (as the check has been
done on installation already).
begin
do_something;
$if check_if_env_is_dev $then
do_some_logging;
$end
do_more_stuff;
end;
Am 12.11.2023 um 16:58 schrieb Tom Lane:
> Ron <ronljohnsonjr@gmail.com> 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
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2023-11-12 16:47 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-11-12 15:32 Conditional compilation Thiemo Kellner <thiemo@gelassene-pferde.biz>
2023-11-12 15:37 ` Ron <ronljohnsonjr@gmail.com>
2023-11-12 15:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-11-12 16:47 ` Thiemo Kellner <thiemo@gelassene-pferde.biz>
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