From: | "J(dot)A(dot)" <postgresql(at)world-domination(dot)com(dot)au> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Erik Wienhold <ewie(at)ewie(dot)name>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: PL/pgSQL doesn't support variables in queries? |
Date: | 2023-05-03 14:34:16 |
Message-ID: | CALT+_gsMv7JuK1WYH9Ubch6d=i6HEOo_02V=ym48=7LiTVa5RA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Ah - I think I'm starting to follow.
what i was _trying_ to do is this
get value from a column and stick it into a variable.
now select * from a _number_ of tables and return a -multi recordsets- from
this single query. I'm not sure if that is the same terminology, in pgsql?
So is this possible?
-JA-
On Wed, 3 May 2023 at 23:29, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "J.A." <postgresql(at)world-domination(dot)com(dot)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
>
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2023-05-03 14:40:19 | Re: PL/pgSQL doesn't support variables in queries? |
Previous Message | Sergey Cherevko | 2023-05-03 13:54:08 | unknown postgres ssl error "could not accept SSL connection: Success" and timeout |