pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Zahir Lalani <ZahirLalani@oliver.agency>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: From Clause Conditional
Date: Thu, 02 Feb 2023 10:29:00 -0500
Message-ID: <1537293.1675351740@sss.pgh.pa.us> (raw)
In-Reply-To: <DB9P251MB05468E6775913F3BE44BC2B3A7D69@DB9P251MB0546.EURP251.PROD.OUTLOOK.COM>
References: <CALfOM6Jk9_OkSqjyXxLNfbu15JC0=W38ba6BcoFAtyVhgBmY4Q@mail.gmail.com>
	<CABUevEwgUedHv1iEXMJnALw0BgJrDasJgUvi5JGpbwRyReRcPA@mail.gmail.com>
	<CALfOM6JaRquBA7ZZtFg-iS4gOh=ju0jDVKSPhpcSXZNe5Zs7Rw@mail.gmail.com>
	<CABUevEzgKkSUF4Tg3ZnbL=T0BmiM6VpfSuOrjUXJENyTJgUDNA@mail.gmail.com>
	<CALfOM6Jf7vXFP0dc9G26K0q4tVSPq-boB6E5NhrWnVc=ogOqfQ@mail.gmail.com>
	<DB9P251MB05468E6775913F3BE44BC2B3A7D69@DB9P251MB0546.EURP251.PROD.OUTLOOK.COM>

Zahir Lalani <ZahirLalani@oliver.agency> writes:
> LEFT JOIN lateral (
> SELECT
>                                 CASE
> WHEN (0 > 0) THEN
> convert_from(crypto_secretbox_open, 'utf8')::JSON
> ELSE
> NULL
> END AS edata
> FROM
>                                 crypto_secretbox_open(coalesce(null, '')::bytea, coalesce(null, '')::bytea,0)
> where (0>0)
> ) enc ON true

> The issue is that, even when the key is 0, the select is still run (its part of a lateral join) and what we need to achieve is to effectively have a conditional where we only run the select if the key > 0 otherwise we return null - I have a brain freeze on this! I am sure there is an easy solution, but right now I can't see it.

Is crypto_secretbox_open marked IMMUTABLE?  I think recent PG versions
are capable of folding this all to a constant if so, whereas older
ones might not have.  If you care about when/whether crypto_secretbox_open
runs, then it must have side-effects, so it shouldn't be IMMUTABLE.

			regards, tom lane





view thread (3+ messages)

Message-ID: <1537293.1675351740@sss.pgh.pa.us>
Permalink:  ../1537293.1675351740@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1537293.1675351740@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, ZahirLalani@oliver.agency
  Subject: Re: From Clause Conditional
  In-Reply-To: <1537293.1675351740@sss.pgh.pa.us>
  References: <CALfOM6Jk9_OkSqjyXxLNfbu15JC0=W38ba6BcoFAtyVhgBmY4Q@mail.gmail.com> <CABUevEwgUedHv1iEXMJnALw0BgJrDasJgUvi5JGpbwRyReRcPA@mail.gmail.com> <CALfOM6JaRquBA7ZZtFg-iS4gOh=ju0jDVKSPhpcSXZNe5Zs7Rw@mail.gmail.com> <CABUevEzgKkSUF4Tg3ZnbL=T0BmiM6VpfSuOrjUXJENyTJgUDNA@mail.gmail.com> <CALfOM6Jf7vXFP0dc9G26K0q4tVSPq-boB6E5NhrWnVc=ogOqfQ@mail.gmail.com> <DB9P251MB05468E6775913F3BE44BC2B3A7D69@DB9P251MB0546.EURP251.PROD.OUTLOOK.COM> <1537293.1675351740@sss.pgh.pa.us>

* 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