pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: S.F. Lee <sflee_tw@yahoo.com>
To: pgsql-interfaces@postgresql.org
Subject: manipulate array wiht ecpg
Date: Mon, 27 Dec 1999 01:51:39 -0800 (PST)
Message-ID: <19991227095139.20990.qmail@web214.mail.yahoo.com> (raw)

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



view thread (5+ messages)  latest in thread

Message-ID: <19991227095139.20990.qmail@web214.mail.yahoo.com>
Permalink:  ../19991227095139.20990.qmail@web214.mail.yahoo.com/
Also on:    postgresql.org/message-id/19991227095139.20990.qmail@web214.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: sflee_tw@yahoo.com
  Subject: Re: manipulate array wiht ecpg
  In-Reply-To: <19991227095139.20990.qmail@web214.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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