Re: ECPG: non-integer constant in group by

Поиск
Список
Период
Сортировка
От Poul Jensen
Тема Re: ECPG: non-integer constant in group by
Дата
Msg-id 450C271B.3050108@gfy.ku.dk
обсуждение исходный текст
Ответ на Re: ECPG: non-integer constant in group by  (Martijn van Oosterhout <kleptog@svana.org>)
Список 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!


В списке pgsql-general по дате отправления:

Предыдущее
От: Peter Bauer
Дата:
Сообщение: Fwd: Multiple entries of same table in pg_class
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Fwd: Multiple entries of same table in pg_class