Skip site navigation (1) Skip section navigation (2)

Re: [SQL] Function Parameters in GROUP BY clause cause errors

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Davidson, Robert" <robdavid(at)amazon(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-bugs(at)postgresql(dot)org
Subject: Re: [SQL] Function Parameters in GROUP BY clause cause errors
Date: 2006-03-22 21:53:48
Message-ID: 20117.1143064428@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-sql
"Davidson, Robert" <robdavid(at)amazon(dot)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

In response to

Responses

pgsql-bugs by date

Next:From: Christian Paul B. CosinasDate: 2006-03-23 01:33:33
Subject: Re: Function Parameters in GROUP BY clause cause errors
Previous:From: Davidson, RobertDate: 2006-03-22 20:11:51
Subject: Function Parameters in GROUP BY clause cause errors

pgsql-sql by date

Next:From: Daniel CauneDate: 2006-03-22 22:34:23
Subject: OUT parameter
Previous:From: Daniel CauneDate: 2006-03-22 21:10:30
Subject: Re: Custom type

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group