From: | Poul Jensen <flyvholm(at)gfy(dot)ku(dot)dk> |
---|---|
To: | Martijn van Oosterhout <kleptog(at)svana(dot)org>, andrew+nonews(at)supernews(dot)com, Joachim Wieland <joe(at)mcknight(dot)de>, pgsql-general General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: ECPG: non-integer constant in group by |
Date: | 2006-09-16 16:32:27 |
Message-ID: | 450C271B.3050108@gfy.ku.dk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Martijn van Oosterhout wrote:
> for (i=0; i<NVARS; i++)
> {
> sprintf(stmt,"SELECT %s FROM beamdata GROUP BY %s;",vars[i],vars[i]);
> EXEC SQL PREPARE mystmt FROM :stmt;
> EXEC SQL EXECUTE mystmt INTO wherever;
> n_occ[i] = sqlca.sqlerrd[2];
> }
>
Apologies. I already read this in the docs, but also forgot it again.
:-| There is a little more to the solution since I need another array to
save the retrieved data after each query. So in the hope to help others,
here's how I did it:
int *all_vars[NVARS];
int *tmp=NULL;
for (i=0; i<NVARS; i++)
{
sprintf(stmt,"SELECT %s FROM beamdata GROUP BY %s;",vars[i],vars[i]);
EXEC SQL PREPARE query FROM :stmt;
EXEC SQL EXECUTE query INTO :tmp;
n_occ[i] = sqlca.sqlerrd[2]; /* Number of rows processed in query */
if ((all_vars[i]=(int *)malloc(n_occ[i]*sizeof(int)))==NULL)
{
fprintf(stderr,"Memory allocation failure\n");
exit(-1);
}
memcpy(all_vars[i], tmp, n_occ[i]*sizeof(int));
EXEC SQL DEALLOCATE PREPARE query;
tmp=NULL;
}
(Remember to free allocated memory when done)
Thanks so much for the help!
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-09-16 16:42:02 | Re: Fwd: Multiple entries of same table in pg_class |
Previous Message | Peter Bauer | 2006-09-16 16:08:55 | Fwd: Multiple entries of same table in pg_class |