Re: ECPG: non-integer constant in group by

From: Poul Jensen <flyvholm(at)gfy(dot)ku(dot)dk>
To: kleptog(at)svana(dot)org, andrew+nonews(at)supernews(dot)com, Joachim Wieland <joe(at)mcknight(dot)de>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: ECPG: non-integer constant in group by
Date: 2006-09-16 11:47:28
Message-ID: 450BE450.1090103@gfy.ku.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you for your replies. My next attempt was:

for (i=0; i<NVARS; i++)
{
sprintf(stmt,"SELECT %s FROM beamdata GROUP BY %s;",vars[i],vars[i]);
EXEC SQL EXECUTE IMMEDIATE :stmt;
n_occ[i] = sqlca.sqlerrd[2];
}

It works, but throws error message "too few parameters" every time. I
need to add INTO <host variable> (I do need to retrieve the data for
later use anyway), but it appears I can't use EXECUTE IMMEDIATE with a
host variable in the statement. So now I can only think of one way:

EXEC SQL SELECT filenm INTO :filenms FROM beamdata GROUP BY filenm;
n_occ[0] = sqlca.sqlerrd[2];
EXEC SQL SELECT yr INTO :yrs FROM beamdata GROUP BY yr;
n_occ[1] = sqlca.sqlerrd[2];
<Repeat for all variables!!>

Works and will get the job done, but so repetitive that it's hard to
accept. Is there no way to get away with a loop?

Poul Jensen

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2006-09-16 12:07:47 Re: ECPG: non-integer constant in group by
Previous Message Martijn van Oosterhout 2006-09-16 09:24:55 Re: ECPG: non-integer constant in group by