pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
selective updates 2+ messages / 1 participants [nested] [flat]
* selective updates @ 2005-12-15 15:06 Gianluca Riccardi <ml-reader@moonwatcher.it> 0 siblings, 1 reply; 2+ messages in thread From: Gianluca Riccardi @ 2005-12-15 15:06 UTC (permalink / raw) To: pgsql-sql 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 <Mark ( dot ) Fenbers ( at ) noaa ( dot ) gov> 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: selective updates @ 2005-12-15 15:35 Gianluca Riccardi <ml-reader@moonwatcher.it> parent: Gianluca Riccardi <ml-reader@moonwatcher.it> 0 siblings, 0 replies; 2+ messages in thread From: Gianluca Riccardi @ 2005-12-15 15:35 UTC (permalink / raw) To: pgsql-sql Gianluca Riccardi wrote: [cut] solved, i used a function giving as result the wanted value from table2.column1 in a UPDATE table1 SET column4=(my_personal_func()) WHERE 'cirteria on table1.column2 table2.column2' ; sorry for making you wasting your time Gianluca Riccardi ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-12-15 15:35 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2005-12-15 15:06 selective updates Gianluca Riccardi <ml-reader@moonwatcher.it> 2005-12-15 15:35 ` Gianluca Riccardi <ml-reader@moonwatcher.it>
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