| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | Zahir Lalani <ZahirLalani(at)oliver(dot)agency> | 
| Cc: | "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> | 
| Subject: | Re: From Clause Conditional | 
| Date: | 2023-02-02 15:29:00 | 
| Message-ID: | 1537293.1675351740@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Zahir Lalani <ZahirLalani(at)oliver(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | veem v | 2023-02-02 19:47:15 | Re: Sequence vs UUID | 
| Previous Message | Erik Wienhold | 2023-02-02 15:28:09 | Re: From Clause Conditional |