Re: sql select query with column 'AS' assignment

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: DzZero <spinzero(at)aero-graphics(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: sql select query with column 'AS' assignment
Date: 2002-02-01 20:01:10
Message-ID: 12208.1012593670@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

DzZero <spinzero(at)aero-graphics(dot)com> writes:
> agi_timesheets=# select distinct
> employee_id,first_name,last_name,date,sum(hours),"R" as job_code from
> timesheet group by employee_id,first_name,last_name,date having job_code
> <> 'H' and job_code <> 'V' and date >= '01-01-2002' and date <=
> '01-15-2002';
> ERROR: Attribute 'R' not found

"R" and 'R' are two quite different things: "R" is a name, 'R' is a
literal constant. Not sure how many of your problems stem from lack
of understanding of this basic point, but quite a few of them do.

> agi_timesheets=# select distinct
> employee_id,first_name,last_name,date,sum(hours),job_code AS "R" from
> timesheet group by employee_id,first_name,last_name,date having job_code
> <> 'H' and job_code <> 'V' and date >= '01-01-2002' and date <=
> '01-15-2002';
> ERROR: Attribute timesheet.job_code must be GROUPed or used in an
> aggregate function

Isn't the error message clear enough? You need to add job_code to
the GROUP BY list.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2002-02-01 20:07:40 Re: A couple binary cursor questions
Previous Message Stephan Szabo 2002-02-01 19:33:54 Re: sql select query with column 'AS' assignment