Search Postgresql Archives

Re: A cronjob for copying a table from Oracle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey Alexander,

Can you post the SQL with call of the function (SQL_UPSERT)
I guess ?

2010/12/10 Alexander Farber <alexander.farber@xxxxxxxxx>
Please help, struggling since hours with this :-(

I've created the following table (columns here and in the proc
sorted alphabetically) to acquire data copied from Oracle:

# \d qtrack
       ÂTable "public.qtrack"
 Column  Â|      ÂType       |  Modifiers
-------------+-----------------------------+---------------
Âappsversion | character varying(30) Â Â Â |
Âbeta_prog  | character varying(20)    |
Âcategory  Â| character varying(120)   Â|
Âcatinfo   | character varying(120)   Â|
Âdetails   | character varying(50)    |
Âdevinfo   | character varying(4000)   |
Âemailid   | character varying(16)    |
Âemail    | character varying(320)   Â|
Âformfactor Â| character varying(10) Â Â Â |
Âid     Â| character varying(20)    | not null
Âimei    Â| character varying(25)    |
Âname    Â| character varying(20)    |
Âosversion  | character varying(30)    |
Âpin     | character varying(12)    |
Âqdatetime  | timestamp without time zone |
Âcopied   Â| timestamp without time zone | default now()
Indexes:
 Â"qtrack_pkey" PRIMARY KEY, btree (id)

And for my "upsert" procedure I get the error:

SQLSTATE[22001]: String data, right truncated: 7 ERROR: Âvalue too
long for type character varying(16)

CONTEXT: ÂSQL statement "update qtrack set APPSVERSION = Â$1 ,
BETA_PROG = Â$2 , CATEGORY = Â$3 , CATINFO = Â$4 , DETAILS = Â$5 ,
DEVINFO = Â$6 , EMAIL = Â$7 , EMAILID = Â$8 , FORMFACTOR = Â$9 , ID =
$10 , IMEI = Â$11 , NAME = Â$12 , OSVERSION = Â$13 , PIN = Â$14 ,
QDATETIME = Â$15 , COPIED = current_timestamp where ID = Â$10 "
PL/pgSQL function "qtrack_upsert" line 2 at SQL statement

My "upsert" procedure is:

create or replace function qtrack_upsert(
   Â_APPSVERSION varchar,
   Â_BETA_PROG  varchar,
   Â_CATEGORY  Âvarchar,
   Â_CATINFO   varchar,
   Â_DETAILS   varchar,
   Â_DEVINFO   varchar,
   Â_EMAILID   varchar,
   Â_EMAIL    varchar,
   Â_FORMFACTOR Âvarchar,
   Â_ID     Âvarchar,
   Â_IMEI    Âvarchar,
   Â_NAME    Âvarchar,
   Â_OSVERSION  varchar,
   Â_PIN     varchar,
   Â_QDATETIME  timestamp
   Â) returns void as $BODY$
   Âbegin
       Âupdate qtrack set
           ÂAPPSVERSION = _APPSVERSION,
           ÂBETA_PROG  = _BETA_PROG,
           ÂCATEGORY  Â= _CATEGORY,
           ÂCATINFO   = _CATINFO,
           ÂDETAILS   = _DETAILS,
           ÂDEVINFO   = _DEVINFO,
           ÂEMAIL    = _EMAIL,
           ÂEMAILID   = _EMAILID,
           ÂFORMFACTOR Â= _FORMFACTOR,
           ÂID     Â= _ID,
           ÂIMEI    Â= _IMEI,
           ÂNAME    Â= _NAME,
           ÂOSVERSION  = _OSVERSION,
           ÂPIN     = _PIN,
           ÂQDATETIME  = _QDATETIME,
           ÂCOPIED   Â= current_timestamp
       Âwhere ID = _ID;

       Âif not found then
           Âinsert into qtrack (
               ÂAPPSVERSION,
               ÂBETA_PROG,
               ÂCATEGORY,
               ÂCATINFO,
               ÂDETAILS,
               ÂDEVINFO,
               ÂEMAIL,
               ÂEMAILID,
               ÂFORMFACTOR,
               ÂID,
               ÂIMEI,
               ÂNAME,
               ÂOSVERSION,
               ÂPIN,
               ÂQDATETIME
           Â) values (
               Â_APPSVERSION,
               Â_BETA_PROG,
               Â_CATEGORY,
               Â_CATINFO,
               Â_DETAILS,
               Â_DEVINFO,
               Â_EMAIL,
               Â_EMAILID,
               Â_FORMFACTOR,
               Â_ID,
               Â_IMEI,
               Â_NAME,
               Â_OSVERSION,
               Â_PIN,
               Â_QDATETIME
           Â);
       Âend if;
   Âend;
$BODY$ language plpgsql;

The weird thing is when I omit the 7th param
in my PHP code as shown below, then it works:

   $sth = $pg->prepare(SQL_UPSERT);
   while (($row = oci_fetch_array($stid,
OCI_NUM+OCI_RETURN_NULLS)) != false) {
       $sth->execute(array(
       Â$row[0],
       Â$row[1],
       Â$row[2],
       Â$row[3],
       Â$row[4],
       Â$row[5],
       Ânull, #$row[6],
       Â$row[7],
       Â$row[8],
       Â$row[9],
       Â$row[10],
       Â$row[11],
       Â$row[12],
       Â$row[13],
       Â$row[14])
       Â);
  Â}

And I'm very confused why it says varying(16) Âin the error message.
It should say varying(4000) instead.

Isn't this a bug? The 6th overflows somehow and gets into 7th

Please save me, I want to go home for weekend
Alex

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



--
// Dmitriy.



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux