ECPG: non-integer constant in group by

From: Poul Jensen <flyvholm(at)gfy(dot)ku(dot)dk>
To: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: ECPG: non-integer constant in group by
Date: 2006-09-15 10:40:49
Message-ID: 450A8331.1000507@gfy.ku.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I actually have two questions.

1) It seems like the fastest way to find the # of distinct elements in a
column is using GROUP BY. With ECPG, if I try
EXEC SQL SELECT filenm FROM beamdata GROUP BY filenm;
I will get "sql error Too few arguments". Why? Can I correct the
query to avoid the error message? (sqlca.sqlerrd[2] does contain the #
of elements in spite of error)

2) The code below was meant to find the # of distinct elements for many
columns, but fails with the message
sql error 'non-integer constant in GROUP BY'
thrown at the EXEC SQL EXECUTE statement. What is the problem? I
suspect it is the definition char *vars[NVARS], but couldn't find any
working alternatives. :-|

--------------------------

#define NVARS 24

int main(int argc, char *argv[]) {

int i, n_occ[NVARS];

EXEC SQL BEGIN DECLARE SECTION;
char *vars[NVARS] = { "filenm", "yr", "mo", "dy", "hr", "mt", "sc",
"us", "stat_id", "bmnum", "channel", "scnflag",
"cp_id", "intt", "intt_us", "frang", "rsep",
"tfreq", "noise", "natten", "nave", "nrang",
"gsct", "isct" };
char dbnm[50], *stmt = "SELECT ? FROM beamdata GROUP BY ?;";
EXEC SQL END DECLARE SECTION;

EXEC SQL WHENEVER SQLWARNING SQLPRINT;
EXEC SQL WHENEVER SQLERROR SQLPRINT;

sprintf(dbnm,"%s",argv[1]);

EXEC SQL CONNECT TO :dbnm;

EXEC SQL PREPARE query FROM :stmt;

for (i=0; i<NVARS; i++)
{
EXEC SQL EXECUTE query USING $vars[i], $vars[i];
n_occ[i] = sqlca.sqlerrd[2];
fprintf(stderr,"# %s: %d\n", vars[i], n_occ[i]);
}

EXEC SQL DEALLOCATE PREPARE query;

EXEC SQL COMMIT;

EXEC SQL DISCONNECT;

return 0;

}

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2006-09-15 10:44:33 Postgresql 7.4 migration to (partially) new disks
Previous Message Martijn van Oosterhout 2006-09-15 09:07:51 Re: berkley sockets