pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
manipulate array wiht ecpg
5+ messages / 2 participants
[nested] [flat]

* manipulate array wiht ecpg
@ 1999-12-27 08:02  S.F. Lee <sflee_tw@yahoo.com>
  0 siblings, 0 replies; 5+ messages in thread

From: S.F. Lee @ 1999-12-27 08:02 UTC (permalink / raw)
  To: pgsql-interfaces

Hi,  
   I am using ecpg to manipulate the whole row in a
table,and I have a problem in array, can anybody give
me a hint or a small test program to process array?

First of all , I create a table(trdday) just as
follow:
  1. edit a trdday.sql file

     CREATE TABLE trdday
     (
       id         int  PRIMARY KEY,
       pv         int[3]
     );
  2. psql -f trdday.sql mydb
  3. I insert a row of data via trdday_insert, but got
following 
     messge :

   sql error Postgres error: ERROR:  Attribute 'pv' is
   of type '_int4' but expression is of type 'int4'
        You will need to rewrite or cast the 
        expression
   line 13.
   Segmentation fault (core dumped)

  4. I insert two rows of data under psql:
     insert into trdday values(1,'{11,22,33}');
     insert into trdday values(2,'{44,55,66}');
  5. Finally, I can find two rows of data in trdday.


Then I write a program (trdday_select.pgc):

   exec sql whenever sqlerror sqlprint;
   exec sql include sqlca;
   main ()
   {
      typedef struct { int pv[3]; } int_array;
      exec sql type int_array is struct { int pv[3];
};
      exec sql begin declare section;  
         struct data
         {
            int id;
            int_array a;
         } temp;
      exec sql end declare section;

      exec sql connect to mydb;
      exec sql select * into :temp from trdday where
id=1;
      exec sql commit;
      exec sql disconnect;
      exit(0);
   }

When I execute the program trdday_select, I got
following error message:

   sql error Not correctly formatted int type:
{11,22,33} line 17.
   sql error Not correctly formatted int type:
{11,22,33} line 17.
   sql error Not correctly formatted int type:
{11,22,33} line 17.


Here is my trdday_insert.pgc:

exec sql whenever sqlerror sqlprint;
/*exec sql include sqlca;*/

main ()
{
   exec sql begin declare section;
      int id;
      int pv[3] = {11,22,33};
   exec sql end declare section;

   exec sql connect to mydb;
   exec sql insert into trdday(id,pv) values(1,:pv);
   exec sql commit;
   exec sql disconnect all;
   exit(0);
}
 

   Thanks
               S.F.Lee

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* manipulate array wiht ecpg
@ 1999-12-27 09:51  S.F. Lee <sflee_tw@yahoo.com>
  0 siblings, 1 reply; 5+ messages in thread

From: S.F. Lee @ 1999-12-27 09:51 UTC (permalink / raw)
  To: pgsql-interfaces

Hi,  
   I am using ecpg to manipulate the whole row in a
table,and I have a problem in array, can anybody give
me a hint or a small test program to process array?

First of all , I create a table(trdday) just as
follow:
  1. edit a trdday.sql file

     CREATE TABLE trdday
     (
       id         int  PRIMARY KEY,
       pv         int[3]
     );
  2. psql -f trdday.sql mydb
  3. I insert a row of data via trdday_insert, but got
following 
     messge :

   sql error Postgres error: ERROR:  Attribute 'pv' is
   of type '_int4' but expression is of type 'int4'
        You will need to rewrite or cast the 
        expression
   line 13.
   Segmentation fault (core dumped)

  4. I insert two rows of data under psql:
     insert into trdday values(1,'{11,22,33}');
     insert into trdday values(2,'{44,55,66}');
  5. Finally, I can find two rows of data in trdday.


Then I write a program (trdday_select.pgc):

   exec sql whenever sqlerror sqlprint;
   exec sql include sqlca;
   main ()
   {
      typedef struct { int pv[3]; } int_array;
      exec sql type int_array is struct { int pv[3];
};
      exec sql begin declare section;  
         struct data
         {
            int id;
            int_array a;
         } temp;
      exec sql end declare section;

      exec sql connect to mydb;
      exec sql select * into :temp from trdday where
id=1;
      exec sql commit;
      exec sql disconnect;
      exit(0);
   }

When I execute the program trdday_select, I got
following error message:

   sql error Not correctly formatted int type:
{11,22,33} line 17.
   sql error Not correctly formatted int type:
{11,22,33} line 17.
   sql error Not correctly formatted int type:
{11,22,33} line 17.


Here is my trdday_insert.pgc:

exec sql whenever sqlerror sqlprint;
/*exec sql include sqlca;*/

main ()
{
   exec sql begin declare section;
      int id;
      int pv[3] = {11,22,33};
   exec sql end declare section;

   exec sql connect to mydb;
   exec sql insert into trdday(id,pv) values(1,:pv);
   exec sql commit;
   exec sql disconnect all;
   exit(0);
}
 

   Thanks
               S.F.Lee




_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] manipulate array wiht ecpg
@ 1999-12-27 13:23  Michael Meskes <meskes@postgreSQL.org>
  parent: S.F. Lee <sflee_tw@yahoo.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Michael Meskes @ 1999-12-27 13:23 UTC (permalink / raw)
  To: S.F. Lee <sflee_tw@yahoo.com>; +Cc: pgsql-interfaces

On Mon, Dec 27, 1999 at 01:51:39AM -0800, S.F. Lee wrote:
>    I am using ecpg to manipulate the whole row in a
> table,and I have a problem in array, can anybody give
> me a hint or a small test program to process array?

Unfortunately this is a known bug in ecpg. It's listed on the TODO list.
However, I have no idea so far how to fix it. The only way you can insert an
array is by listing its members. That is you have to create your insert
statement via sprintf for instance and use exec sql execute immediate.

Sorry. I will fix it as soon as I find a solution.

The problem is that ecpg also allows inserting the whole array as single
integers by only listing the array.

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] 5+ messages in thread

* Re: [INTERFACES] manipulate array wiht ecpg
@ 1999-12-29 06:40  S.F. Lee <sflee_tw@yahoo.com>
  0 siblings, 1 reply; 5+ messages in thread

From: S.F. Lee @ 1999-12-29 06:40 UTC (permalink / raw)
  To: Michael Meskes <meskes@postgreSQL.org>; +Cc: pgsql-interfaces

I have solved the problem by mapping a character array
into integer array:

  struct data   {
    int id;
    char a[100];
  } temp;
After getting temp from exec sql select ....., I use
strtol() to convert temp.a into a integer array, and 
it works! I now have another problem that is I can get

the tuples by sqlca.sqlerrd[2], but how can I get the
type of each field that has been selected? In libpq++
FieldType(n) can get the type of field, how about in 
ecpg?

  Thanks
             S.F.Lee
--- Michael Meskes <meskes@postgreSQL.org> wrote:
> On Mon, Dec 27, 1999 at 01:51:39AM -0800, S.F. Lee
> wrote:
> >    I am using ecpg to manipulate the whole row in
> a
> > table,and I have a problem in array, can anybody
> give
> > me a hint or a small test program to process
> array?
> 
> Unfortunately this is a known bug in ecpg. It's
> listed on the TODO list.
> However, I have no idea so far how to fix it. The
> only way you can insert an
> array is by listing its members. That is you have to
> create your insert
> statement via sprintf for instance and use exec sql
> execute immediate.
> 
> Sorry. I will fix it as soon as I find a solution.
> 
> The problem is that ecpg also allows inserting the
> whole array as single
> integers by only listing the array.
> 
> 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!
> 

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://messenger.yahoo.com



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] manipulate array wiht ecpg
@ 1999-12-29 12:34  Michael Meskes <meskes@postgreSQL.org>
  parent: S.F. Lee <sflee_tw@yahoo.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Michael Meskes @ 1999-12-29 12:34 UTC (permalink / raw)
  To: S.F. Lee <sflee_tw@yahoo.com>; +Cc: pgsql-interfaces

On Tue, Dec 28, 1999 at 10:40:52PM -0800, S.F. Lee wrote:
> After getting temp from exec sql select ....., I use
> strtol() to convert temp.a into a integer array, and 
> it works! I now have another problem that is I can get

Still I would prefer a better handling by ecpg. :-)

> the tuples by sqlca.sqlerrd[2], but how can I get the
> type of each field that has been selected? In libpq++
> FieldType(n) can get the type of field, how about in 
> ecpg?

I do not know a way other than querying the data dictionary. What does the
standard say? Should we return such info?

What do other RDBMS do in this scenario?

Is there a way I can give this info back anyway. Right now I cannot imagine
one since we give back the whole tuple at once. Where shall we store these
per attribute infos?

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] 5+ messages in thread


end of thread, other threads:[~1999-12-29 12:34 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-12-27 08:02 manipulate array wiht ecpg S.F. Lee <sflee_tw@yahoo.com>
1999-12-27 09:51 manipulate array wiht ecpg S.F. Lee <sflee_tw@yahoo.com>
1999-12-27 13:23 ` Michael Meskes <meskes@postgreSQL.org>
1999-12-29 06:40 Re: [INTERFACES] manipulate array wiht ecpg S.F. Lee <sflee_tw@yahoo.com>
1999-12-29 12:34 ` 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