[INTERFACES] my problems with ecpg and arrays

From: "Coleman, Andrew" <colemana(at)navo(dot)navy(dot)mil>
To: pgsql-interfaces(at)postgreSQL(dot)org
Subject: [INTERFACES] my problems with ecpg and arrays
Date: 1999-11-08 16:39:12
Message-ID: 78166D547FD9D2119FA700805F9FA971C0E9A0@navont3.navo.navy.mil
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces


Hi,
I'm having problems loading (insert into ..) a c array into a postgres
table.
I have tried all the variations on syntax I can think of, and searched for
the
answer... and either didn't find it or didn't recognize it..

SHORT version:
How do I replace {1,2...} with a c array,
exec sql insert into testtab (fname,fid,farr) values
(:fname,:fid,'{1,2,3,4,5,6,7,8,9}');
?

LONG,LONG version:
typos are mine (I have to retype from the system I'm running postgres :( )
I can do this in psql:
create type int2array
(input=array_in,output=array_out,internallength=variable,element=int2);
create table sampletab2 (id int4, narr int2array);
insert into sampletab2 (id,narr) values (12,'{3,2}');
and everything looks ok with both \d sampletab2 and select * from sampletab2

And this code works great:
#include <stdio.h>
#include <libpq-fe.h>
#include <math.h>

exec sql whenever sqlerror sqlprint;
exec sql include sqlca;

exec sql begin declare section;
int fid;
int fidarr[10];
varchar[40];
varchar sqlcom[80];
exec sql end declare section;

main(){
int ii;
printf("Begin \n");
fid=5;
for (ii=0;ii<=9;ii++) {fidarr[ii]=ii;printf("fidarr[%d]=%d
\n",ii,fidarr[ii]);};
fname.len=sprintf(fname.arr,"doodah day");
printf("fid equals : %d \n",fid);
exec sql connect to testdb1;
exec sql create table testtab (fname varchar(40),fid int, fidarr int[10]);
exec sql insert into testtab (fname,fid,farr) values
(:fname,:fid,'{1,2,3,4,5,6,7,8,9}');
exec sql commit;
exec sql disconnect;
printf ("Done \n");
}

How do a do something like:
exec sql insert into testtab (fname,fid,farr) values (:fname,:fid,:fidarr);

??
Thanks (and sorry for the long post)
andrew.

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Ravi 1999-11-08 19:51:55 postgre and sqlerror handling
Previous Message Robert Hiltibidal 1999-11-08 15:38:40 openssl