Plperl Question

From: "Chris Coleman" <ChristopherC(at)eurocom(dot)co(dot)uk>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Plperl Question
Date: 2007-03-14 16:06:41
Message-ID: 538A2AED987D2F458E7FDDAEE5E1E13537FA1A@secure.eurocom.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-03-14 16:12:13 Re: DST failing on 8.1.3
Previous Message Guy Fraser 2007-03-14 16:05:19 Re: DST failing on 8.1.3