X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C3E1D9DCC05 for ; Thu, 15 Dec 2005 11:04:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19723-06 for ; Thu, 15 Dec 2005 11:04:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp20.libero.it (smtp20.libero.it [193.70.192.147]) by postgresql.org (Postfix) with ESMTP id A9F2E9DCC00 for ; Thu, 15 Dec 2005 11:04:10 -0400 (AST) Received: from localhost (172.16.1.83) by smtp20.libero.it (7.0.027-DD01) id 439D916F0063A64F for pgsql-sql@postgresql.org; Thu, 15 Dec 2005 16:04:12 +0100 Received: from smtp3.libero.it ([172.16.1.53]) by localhost (asav24.libero.it [193.70.193.11]) (amavisd-new, port 10024) with ESMTP id 01633-01-8 for ; Thu, 15 Dec 2005 16:04:09 +0100 (CET) Received: from [172.16.0.5] (ppp-5-206.24-151.libero.it [151.24.206.5]) by smtp3.libero.it (Postfix) with ESMTP id 58E5EABE6A for ; Thu, 15 Dec 2005 16:04:08 +0100 (MET) Message-ID: <43A18658.8030202@moonwatcher.it> Date: Thu, 15 Dec 2005 16:06:00 +0100 From: Gianluca Riccardi User-Agent: Mozilla/5.0 (X11; U; Linux i686; it-IT; rv:1.7.8) Gecko/20050927 Debian/1.7.8-1sarge3 X-Accept-Language: it MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: selective updates Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Scanned: with antispam and antivirus automated system at libero.it X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/128 X-Sequence-Number: 23670 sorry for posting a new opening 'thread', but my subscribing to the ml is later than a post with the subject 'APPEND INTO?' dated Thu, 01 Dec 2005 10:32:08 -0500 so i can't make reply to that. follows a copy of that post Mark Fenbers writes: > I want to SELECT INTO mytable WHERE (criteria are met), except that I > want to APPEND into an existing table the rows that are selected, > instead of creating a new table (which SELECT INTO will do). How can > this be done? >INSERT INTO foo SELECT whatever > regards, tom lane and what if we need to be selective when inserting rows let's say we have the following test-db CREATE TABLE table1 ( column1 int, column2 varchar(20), column3 numeric, column4 int ); CREATE TABLE table2 ( column1 int, column2 varchar(20) ); and the population is: test-db=# SELECT * from table1; column1 | column2 | column3 | column4 ---------+-----------------+---------+--------- 1 | some name | 3.5 | 1 | some other | 4.7 | 2 | some some | 3 | 2 | some else | 3 | 3 | some thing | 8.5 | 3 | some thing else | 8.3 | (6 righe) test-db=# test-db=# SELECT * from table2; column1 | column2 ---------+------------ 1 | some info 1 | some info1 1 | some info2 2 | some info3 2 | some info4 2 | some info5 (6 righe) test-db=# now we need to update the table1.column4 to store the values from table2.column1 when table1.column2 table2.column2 match a given citeria i think we would need a transaction block andor SQL functions, but i didn't find myself a solution yet. Gianluca Riccardi p.s. i'm using PostgreSQL 7.4.7