pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feed[INTERFACES] my problems with ecpg and arrays
6+ messages / 4 participants
[nested] [flat]
* [INTERFACES] my problems with ecpg and arrays
@ 1999-11-08 16:39 Coleman, Andrew <colemana@navo.navy.mil>
0 siblings, 2 replies; 6+ messages in thread
From: Coleman, Andrew @ 1999-11-08 16:39 UTC (permalink / raw)
To: 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.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] my problems with ecpg and arrays
@ 1999-11-10 14:12 Michael Meskes <meskes@postgresql.org>
parent: Coleman, Andrew <colemana@navo.navy.mil>
1 sibling, 0 replies; 6+ messages in thread
From: Michael Meskes @ 1999-11-10 14:12 UTC (permalink / raw)
To: Coleman, Andrew <colemana@navo.navy.mil>; +Cc: pgsql-interfaces
On Mon, Nov 08, 1999 at 10:39:12AM -0600, Coleman, Andrew wrote:
> 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..
This certainly looks like a bug. I will take care of it if I find the time
sometimes. Sorry, but I'm currently very busy.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De | Use PostgreSQL!
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] my problems with ecpg and arrays
@ 1999-11-12 13:10 Michael Meskes <michael@fam-meskes.de>
parent: Coleman, Andrew <colemana@navo.navy.mil>
1 sibling, 0 replies; 6+ messages in thread
From: Michael Meskes @ 1999-11-12 13:10 UTC (permalink / raw)
To: Coleman, Andrew <colemana@navo.navy.mil>; +Cc: pgsql-interfaces
On Mon, Nov 08, 1999 at 10:39:12AM -0600, Coleman, Andrew wrote:
> 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..
I'm afraid you find a real problem here. I just didn't think about inserting
arrays. If you give ecpg an array of int it inserts every single value as
one int. That means:
insert into foo(bar) values(:intarray)
is equal to:
for (i=0;i<maxarray;i++)
insert into foo(bar) values(:intarray[i])
How shall ecpg see that this time it is meant to insert the whole array?
Anyone with an idea?
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De | Use PostgreSQL!
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] my problems with ecpg and arrays
@ 1999-11-12 16:10 Michael Meskes <meskes@postgresql.org>
0 siblings, 0 replies; 6+ messages in thread
From: Michael Meskes @ 1999-11-12 16:10 UTC (permalink / raw)
To: pgsql-interfaces
On Mon, Nov 08, 1999 at 10:39:12AM -0600, Coleman, Andrew wrote:
> 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..
I'm afraid you find a real problem here. I just didn't think about inserting
arrays. If you give ecpg an array of int it inserts every single value as
one int. That means:
insert into foo(bar) values(:intarray)
is equal to:
for (i=0;i<maxarray;i++)
insert into foo(bar) values(:intarray[i])
How shall ecpg see that this time it is meant to insert the whole array?
Anyone with an idea?
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De | Use PostgreSQL!
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] my problems with ecpg and arrays
@ 1999-11-15 14:27 Coleman, Andrew <colemana@navo.navy.mil>
0 siblings, 1 reply; 6+ messages in thread
From: Coleman, Andrew @ 1999-11-15 14:27 UTC (permalink / raw)
To: pgsql-interfaces
Thanks for looking into it. For the code I'm working on, it's no problem to
work around (messy, but
no problem).
>I'm afraid you find a real problem here. I just didn't think about
inserting
>arrays. If you give ecpg an array of int it inserts every single value as
>one int. That means:
>
>insert into foo(bar) values(:intarray)
>
>is equal to:
>
>for (i=0;i<maxarray;i++)
> insert into foo(bar) values(:intarray[i])
>How shall ecpg see that this time it is meant to insert the whole array?
>
>Anyone with an idea?
I'm guessing you're mostly directing that at people who are atleast vaguely
familiar with the
way pg and ecpg works internally ;)
>
>Michael
Thanks again (both for looking into it and for ecpg itself),
andrew.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [INTERFACES] my problems with ecpg and arrays
@ 1999-11-16 15:26 Michael Meskes <meskes@postgreSQL.org>
parent: Coleman, Andrew <colemana@navo.navy.mil>
0 siblings, 0 replies; 6+ messages in thread
From: Michael Meskes @ 1999-11-16 15:26 UTC (permalink / raw)
To: Coleman, Andrew <colemana@navo.navy.mil>; +Cc: pgsql-interfaces
On Mon, Nov 15, 1999 at 08:27:36AM -0600, Coleman, Andrew wrote:
> Thanks for looking into it. For the code I'm working on, it's no problem to
> work around (messy, but
> no problem).
Hopefully I find a better solution. :-)
> I'm guessing you're mostly directing that at people who are atleast vaguely
> familiar with the
> way pg and ecpg works internally ;)
Yes. :-)
> Thanks again (both for looking into it and for ecpg itself),
I'm glad it is actually used.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De | Use PostgreSQL!
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~1999-11-16 15:26 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-11-08 16:39 [INTERFACES] my problems with ecpg and arrays Coleman, Andrew <colemana@navo.navy.mil>
1999-11-10 14:12 ` Michael Meskes <meskes@postgresql.org>
1999-11-12 13:10 ` Michael Meskes <michael@fam-meskes.de>
1999-11-12 16:10 Re: [INTERFACES] my problems with ecpg and arrays Michael Meskes <meskes@postgresql.org>
1999-11-15 14:27 Re: [INTERFACES] my problems with ecpg and arrays Coleman, Andrew <colemana@navo.navy.mil>
1999-11-16 15:26 ` Michael Meskes <meskes@postgreSQL.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox