Re: PL/pgSQL doesn't support variables in queries?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: PL/pgSQL doesn't support variables in queries?
Дата
Msg-id 2955822.1683120535@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: PL/pgSQL doesn't support variables in queries?  ("J.A." <postgresql@world-domination.com.au>)
Ответы Re: PL/pgSQL doesn't support variables in queries?
Список pgsql-general
"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



В списке pgsql-general по дате отправления:

Предыдущее
От: Erik Wienhold
Дата:
Сообщение: Re: PL/pgSQL doesn't support variables in queries?
Следующее
От: Sergey Cherevko
Дата:
Сообщение: iso-8859-1 postgres ssl error "could not accept SSL connection: Success" and timeout