From: Tom Lane <tgl@sss.pgh.pa.us>
To: J.A. <postgresql@world-domination.com.au>
Cc: Erik Wienhold <ewie@ewie.name>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: PL/pgSQL doesn't support variables in queries?
Date: Wed, 03 May 2023 09:28:55 -0400
Message-ID: <2955822.1683120535@sss.pgh.pa.us> (raw)
In-Reply-To: <CALT+_gtnW+6GJ95EVJtP9P5fVHfYaOSX1fsrsRddshGob=kCkg@mail.gmail.com>
References: <CALT+_gvfHtF5jqQg+J2suw3hOEh3ZWjZQDB8jJ945o4b1ekyyQ@mail.gmail.com>
<658455455.1152531.1683117585087@office.mailbox.org>
<CALT+_gtnW+6GJ95EVJtP9P5fVHfYaOSX1fsrsRddshGob=kCkg@mail.gmail.com>
"J.A." <postgresql@world-domination.com.au> writes:
> I must admit, I did try doing something like you suggested Erik. I tried
> things like:
> DO $$
> DECLARE
> v_application_id uuid;
> BEGIN
> SELECT application_id INTO v_application_id FROM applications
> WHERE code = 'pg-test-cc';
> SELECT * FROM application_foo WHERE application_id =
> v_application_id;
> -- more SELECT * FROM child tables....
> END $$;
> but that never worked, with warning:
> ERROR: query has no destination for result data HINT: If you want to
> discard the results of a SELECT, use PERFORM instead. CONTEXT: PL/pgSQL
> function inline_code_block line 7 at SQL statement SQL state: 42601
Note that that is complaining about your second try, not your first.
You need to put the result of the SELECT somewhere. INTO is fine
if it's a single-row result. Otherwise, consider looping through
the result with a FOR loop. Again, there are plenty of examples
in the manual.
regards, tom lane
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, postgresql@world-domination.com.au, ewie@ewie.name
Subject: Re: PL/pgSQL doesn't support variables in queries?
In-Reply-To: <2955822.1683120535@sss.pgh.pa.us>
References: <CALT+_gvfHtF5jqQg+J2suw3hOEh3ZWjZQDB8jJ945o4b1ekyyQ@mail.gmail.com> <658455455.1152531.1683117585087@office.mailbox.org> <CALT+_gtnW+6GJ95EVJtP9P5fVHfYaOSX1fsrsRddshGob=kCkg@mail.gmail.com> <2955822.1683120535@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