ECPG: non-integer constant in group by - Mailing list pgsql-general

From Poul Jensen
Subject ECPG: non-integer constant in group by
Date
Msg-id 450A8331.1000507@gfy.ku.dk
Whole thread Raw
Responses Re: ECPG: non-integer constant in group by
List 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 by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: berkley sockets
Next
From: Achilleas Mantzios
Date:
Subject: Postgresql 7.4 migration to (partially) new disks