Re: plpgsql; execute query inside exists

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: plpgsql; execute query inside exists
Дата
Msg-id CAF-3MvOkChhyo06nf2UtmWU9K1_Zy=+YU7+++9PCGR+GbqkcVA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: plpgsql; execute query inside exists  (jozsef.kurucz@invitel.hu)
Список pgsql-general
On 18 October 2011 09:57,  <jozsef.kurucz@invitel.hu> wrote:
> Hi,
>
> Thanks for the reply!
> But I don't want to check if the table exists, I want to see the
> result of the SELECT query, if a row presence or not.

So you want to check that the table contains data? In that case it
makes no sense to create the table if it doesn't contain data. It may
very well exist already.

> The tmp_tbl is a dynamic generated table name, but when I write the
> code without EXECUTE, I get syntax error too.

They were explaining why you got the error, they were not telling you
to leave out EXECUTE for dynamic SQL.

> In this case how can I check if a SELECT has result or not?
>
> SELECT INTO rndmd5 md5(random()::text);
>
> tmp_tbl := 'tbl_tmp_' || rndmd5;
>
>
> IF NOT EXISTS(SELECT * FROM tmp_tbl)
>   THEN
>     END IF;

You really should at least limit the possible amount of results from
that SELECT statement. You're not interested in the results.

Anyway, the way to do this in plpgsql is:

EXECUTE SELECT * FROM tmp_tbl LIMIT 1;
IF NOT FOUND THEN
    ...
END IF;

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

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

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: How to correct: ERROR: permission denied: "RI_ConstraintTrigger_24966" is a system trigger
Следующее
От: Craig Ringer
Дата:
Сообщение: Log or notice values or rows that cause a constraint violation