Re: sql select query with column 'AS' assignment - Mailing list pgsql-hackers

From Tom Lane
Subject Re: sql select query with column 'AS' assignment
Date
Msg-id 12208.1012593670@sss.pgh.pa.us
Whole thread Raw
In response to sql select query with column 'AS' assignment  (DzZero <spinzero@aero-graphics.com>)
List pgsql-hackers
DzZero <spinzero@aero-graphics.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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: PostgreSQL crashes with Qmail-SQL
Next
From: Bruno Wolff III
Date:
Subject: Re: PostgreSQL crashes with Qmail-SQL