[INTERFACES] my problems with ecpg and arrays - Mailing list pgsql-interfaces

From Coleman, Andrew
Subject [INTERFACES] my problems with ecpg and arrays
Date
Msg-id 78166D547FD9D2119FA700805F9FA971C0E9A0@navont3.navo.navy.mil
Whole thread Raw
Responses Re: [INTERFACES] my problems with ecpg and arrays  (Michael Meskes <meskes@postgresql.org>)
Re: [INTERFACES] my problems with ecpg and arrays  (Michael Meskes <michael@fam-meskes.de>)
List 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.


pgsql-interfaces by date:

Previous
From: Robert Hiltibidal
Date:
Subject: openssl
Next
From: "Ravi"
Date:
Subject: postgre and sqlerror handling