I have a proc sql code that I am connecting to a Postgresql database and pulling data from. I have simplified the code and trying it on its on, but when I submit it through Proc SQL, I get an error. When I submit the same code directly into Postgresql it works just fine. Any ideas?
The simplified code is :
proc SQL;
Connect to odbc(dsn ='database' uid =guest pwd =guest );
Select * from connection to odbc
(Select date(date_time)as iDate
,equipmentsernum
,AVG(xxx)
,AVG(yyy)
From "tablename"
Where date_time >= '2007-01-01'
Group By equipmentsernum, iDate
);
Disconnect from odbc;
Simplified - I am pulling daily averages for fields. I cast the timestamp date_time into just date and group by iDate. As mentioned, when I submit this directly to Postgresql, the code works, but when submitted through Proc SQL I get the following error:
ERROR: CLI describe error: ERROR: column "tablename.date_time" must appear in the GROUP BY clause or
be used in an aggregate function; No query has been executed with that handle
This is a normal error that occurs when you group by with aggregates - you need to
include all non-aggregates in the group by. However, I have included iDate in the group by and the query works directly.
Any suggestions would be appreciated.
Regards,
Fred