Re: Multiple SELECT statements Using One WITH statement

From: Josef Šimánek <josef(dot)simanek(at)gmail(dot)com>
To: Avi Weinberg <AviW(at)gilat(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Multiple SELECT statements Using One WITH statement
Date: 2022-01-20 15:13:31
Message-ID: CAFp7Qwp1Ymz0ZD7z2vN7D+3+xd4Z8tFXK+PSbD2XNePdT1GZmA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

čt 20. 1. 2022 v 13:48 odesílatel Avi Weinberg <AviW(at)gilat(dot)com> napsal:
>
> Hi,
Hello!
>
>
> Can I have multiple select statements using one WITH statement?
>
>
>
> WITH t AS (
>
> Select A, B from …
>
> )
>
> SELECT A into tableA FROM t where ….;
>
>
>
> SELECT B into tableB FROM t where ….;
>

I think it is not possible that way. Instead you can "cache" the query
result into a temporary table. CREATE TEMPORARY TABLE ... ON COMMIT
DROP could be useful here. There is simple example mentioned in this
(https://stackoverflow.com/a/52384424/319233) stackoverflow answer.
>
> IMPORTANT - This email and any attachments is intended for the above named addressee(s), and may contain information which is confidential or privileged. If you are not the intended recipient, please inform the sender immediately and delete this email: you should not copy or use this e-mail for any purpose nor disclose its contents to any person.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Johannes Graën 2022-01-20 15:28:29 Re: Multiple SELECT statements Using One WITH statement
Previous Message Avi Weinberg 2022-01-20 14:42:13 RE: Multiple SELECT statements Using One WITH statement