Re: Function Parameters in GROUP BY clause cause errors

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Function Parameters in GROUP BY clause cause errors
Дата
Msg-id 20117.1143064428@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Function Parameters in GROUP BY clause cause errors  ("Davidson, Robert" <robdavid@amazon.com>)
Ответы Re: Function Parameters in GROUP BY clause cause errors  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
"Davidson, Robert" <robdavid@amazon.com> writes:
> ERROR:  column "em.email_creation_datetime" must appear in the GROUP BY =
> clause or be used in an aggregate function
> CONTEXT:  SQL statement " select to_char(to_timestamp(EXTRACT(HOUR FROM =
> em.email_creation_datetime) || ':' || (EXTRACT(MINUTE FROM =
> em.email_creation_datetime)::integer/ $1 ) *  $2 , 'HH24:MI'), =
> 'HH24:MI') as TheInterval from test em group by =
> to_char(to_timestamp(EXTRACT(HOUR FROM em.email_creation_datetime) || =
> ':' || (EXTRACT(MINUTE FROM em.email_creation_datetime)::integer/ $3 ) * =
>  $4 , 'HH24:MI') , 'HH24:MI')"
> PL/pgSQL function "emailbyinterval" line 3 at for over select rows

Hmm, this seems like a plpgsql deficiency.  It feels it can generate a
separate parameter symbol ($n) for each occurrence of each variable it
passes into a SQL query.  But for this query to be legal, the two
instances of IntervalMinutes have to be represented by the *same*
parameter symbol (notice they are not in the regurgitated query).

It would be more efficient anyway to not generate multiple parameters
for the same value, so we oughta fix this.

In the short run, the only workaround I can think of for you is to run
the query using EXECUTE.
        regards, tom lane


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

Предыдущее
От: "Daniel Caune"
Дата:
Сообщение: Re: Custom type
Следующее
От: "Daniel Caune"
Дата:
Сообщение: OUT parameter