Plperl Question - Mailing list pgsql-general

From Chris Coleman
Subject Plperl Question
Date
Msg-id 538A2AED987D2F458E7FDDAEE5E1E13537FA1A@secure.eurocom.me.uk
Whole thread Raw
Responses Re: Plperl Question  ("Stuart Cooper" <stuart.cooper@gmail.com>)
List pgsql-general
Hi,

I'm trying to write a plperl function to copy the new row e.g. NEW in
plpgsql into another table.  I was looking for a similar effect to the 

INSERT INTO blah VALUES (NEW.*) 

Syntax that can be used in plpgsql.  So fat the best I have come up with
is:

$collist = "";
$vallist = "";
while (($col, $val) = each(%{$_TD->{new}}))
{
    $collist .= ($col.",");

    #Need to fix issues here with quoting in the value list.
    $vallist .= ("'".$val."',");
}
chop($collist);
chop($vallist);

However, this leads to issues with numerical columns being quoted, and
worse still NULL numerical column being entered as '' which results in
"Invalid syntax for integer" errors.

The only solution I can see at present is to look up the type of each
column name in the pg_catalog tables, and based upon this, quote as
necessary.

Does anyone have any better suggestions of how to approach this problem?

Many thanks 
Chris 

--------------------------------
Chris Coleman
Programmer 
Information Systems
Room PKL1 Phone 369
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

This e-mail is confidential and may be read only by the intended recipient.
If you are not the intended recipient, please do not forward, copy or take
any action based on it and, in addition, please delete this email and
inform the sender.
We cannot be sure that this e-mail or its attachments are free from
viruses.  In keeping with good computing practice, please ensure that
you take adequate steps to check for any viruses.  Before replying
or sending any email to us, please consider that the internet is inherently
insecure and is an inappropriate medium for certain kinds of information.
We reserve the right to access and read all e-mails and attachments
entering or leaving our systems.

Registered office: Eurocom House, Ashbourne Road, Derby DE22 4NB Company number: 01574696. 


pgsql-general by date:

Previous
From: Guy Fraser
Date:
Subject: Re: DST failing on 8.1.3
Next
From: Tom Lane
Date:
Subject: Re: DST failing on 8.1.3