ECPG: non-integer constant in group by
| От | Poul Jensen | 
|---|---|
| Тема | ECPG: non-integer constant in group by | 
| Дата | |
| Msg-id | 450A8331.1000507@gfy.ku.dk обсуждение исходный текст | 
| Ответы | Re: ECPG: non-integer constant in group by | 
| Список | 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;
}
		
	В списке pgsql-general по дате отправления: