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 Adrian,

2010/12/10 Adrian Klaver <adrian.klaver@xxxxxxxxx>
On Friday 10 December 2010 8:51:19 am Alexander Farber wrote:
> 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


Looks like you got your EMAIL and EMAILID reversed. In your argument list
EMAILID is 7th but it is getting the 8th variable, the reverse for EMAIL.
Yes, but he refers arguments by name, rather than number. UPDATE statement
seems to be correct in the function definition.

>
> 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



--
Adrian Klaver
adrian.klaver@xxxxxxxxx

--
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