From: Venelin Arnaudov <v.arnaudov@prosyst.com>
To: pgsql-sql@postgresql.org
Subject: Problems with bulk update
Date: Thu, 27 Sep 2007 10:21:54 +0200
Message-ID: <46FB6822.9060507@prosyst.com> (raw)
Hi
I want to update the values of one column of a table based on the
matches in a second table
data_table:
field1,
field2_new,
...
field2_old
mapping_table:
new_id,
old_id
something like
update table1
set table1.field2_new=table2.new_id
from table2
where table1.field2_old=table2.old_id;
Is this possible with postgre without writing php script that cycles the
data_table?
I have even created a function
CREATE FUNCTION get_new_field2(integer) RETURNS integer AS
'SELECT new_id FROM mapping WHERE old_id= $1 limit 1'
LANGUAGE SQL;
and tried
UPDATE table1 set field2_new=get_new_field2(field2_old);
but it did not work :( It seems that the function is not executed for
each record of the data_table.
Kindest regards,
Venelin Arnaudov
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-sql@postgresql.org
Cc: v.arnaudov@prosyst.com
Subject: Re: Problems with bulk update
In-Reply-To: <46FB6822.9060507@prosyst.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