Re: variable use for selects

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: variable use for selects
Дата
Msg-id 26773.1246857273@sss.pgh.pa.us
обсуждение исходный текст
Ответ на variable use for selects  ("Allen, Danni" <Danni.Allen@Avnet.com>)
Ответы Re: variable use for selects  ("Allen, Danni" <Danni.Allen@Avnet.com>)
Список pgsql-novice
"Allen, Danni" <Danni.Allen@Avnet.com> writes:
> I'm doing the following:

> myseriestable := myleagueid || '_' || myleaguename || '_series';
> myseriesid := (select seriesid from myseriestable order by seriesid desc limit 1);

You can't use a variable where a table name is required.

If you are absolutely intent on doing this, you could construct the
whole query (not just the table name) as a string and EXECUTE it.
However, my advice would be to rethink your database schema.  Anytime
you have N tables with the same layout, you should consider whether
they oughtn't be one table with an extra key column (or maybe two
columns, in this example).  What you're doing is basically simulating
the extra key columns by hand, and it is generally *not* any kind of
efficiency win to do that.

            regards, tom lane

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

Предыдущее
От: Tguru
Дата:
Сообщение: Re: Problems using psql--Fatal password authentication failed
Следующее
От: Ms swati chande
Дата:
Сообщение: Problem with createdb