Re: [SQL] update from join

2009-05-14 Thread Rob Sargent
I wonder if this works: update stock s set s_superceded = true where s.s_updated < (select max(t.s_updated) from stock t where t.s_vin = s.s_vin) On Thu, May 14, 2009 at 7:27 AM, Gary Stainburn < gary.stainb...@ringways.co.uk> wrote: > I know I should be able to do this but my brain's mashed

[SQL] update from join

2009-05-14 Thread Gary Stainburn
I know I should be able to do this but my brain's mashed today I have a stock table with s_stock_no varchar primary key s_vin varchar s_updated timestamp s_supercededboolean It is possible for the same vin to exist on stock if we have s

Re: [SQL] UPDATE .. FROM

2008-03-07 Thread Tom Lane
"Markus Bertheau" <[EMAIL PROTECTED]> writes: > I'm kind of stuck as to why postgresql doesn't understand what I mean in the > following queries: > UPDATE tag_data td SET td.usage_counter = td.usage_counter + 1 FROM > tag_list_tag_data ltd WHERE ltd.tag_id = td.id AND ltd.id = 102483; > ERROR: c

[SQL] UPDATE .. FROM

2008-03-07 Thread Markus Bertheau
I'm kind of stuck as to why postgresql doesn't understand what I mean in the following queries: UPDATE tag_data td SET td.usage_counter = td.usage_counter + 1 FROM tag_list_tag_data ltd WHERE ltd.tag_id = td.id AND ltd.id = 102483; ERROR: column "td" of relation "tag_data" does not exist LINE 1:

Re: [SQL] update from select

2007-10-29 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > Hash Join (cost=10827.45..25950.05 rows=4906 width=1191) (actual > time=586.251..2852.691 rows=111306 loops=1) > ... > Total runtime: 633548.404 ms So you're worried about the wrong thing entirely. The query is taking less than 3 seconds, which may be reasonable con

Re: [SQL] update from select

2007-10-29 Thread Pavel Stehule
ail_dvd.release_date. Maybe there is other problem. The casting from (probably) date to text in releasedate column. Is it correct? what is original type for releasedate column? Pavel > > Thaks for helping!! Bye the way, we are changing our system from MSSQL2000 > to Postgres :-)! >

Re: [SQL] update from select

2007-10-29 Thread dev
tal runtime: 1039998.325 ms *** Thaks for helping!! Bye the way, we are changing our system from MSSQL2000 to Postgres :-)! Regards Reto -Ursprüngliche Nachricht- Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Im Auftrag von A. Kr

Re: [SQL] update from select

2007-10-29 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > Is there a better way to do this update: > UPDATE table1 SET column2 = temp_table.column2, column3 = > temp_table.column3, column4 = CAST(temp_table.column4 AS date) FROM > ( > SELECT DISTINCT > table2.column1, > table2.column2, > table2.column3, > table2.column4

Re: [SQL] update from select

2007-10-29 Thread Pavel Stehule
Hello you use corelated subquery and that is slow for thausands rows. Use PostgreSQL's extension UPDATE table1 SET column2 = t,colum2, FROM table2 t WHERE table1.column1 = t.column1 and t.column4 is not null and ... http://www.postgresql.org/docs/8.2/interactive/sql-update.html Regards Pav

Re: [SQL] update from select

2007-10-29 Thread A. Kretschmer
am Mon, dem 29.10.2007, um 10:18:38 +0100 mailte [EMAIL PROTECTED] folgendes: > > WHERE table1.column1 = temp_table.column1; table1.column1 and temp_table.column1 have the same type? > > > > The select by it?s own takes around 1 second. The Update is around 120?000 > rows. I got an index on

[SQL] update from select

2007-10-29 Thread dev
Hello I have a performance problem with an SQL statement. Is there a better way to do this update: UPDATE table1 SET column2 = temp_table.column2, column3 = temp_table.column3, column4 = CAST(temp_table.column4 AS date) FROM ( SELECT DISTINCT table2.column1, table2.column2, table2

[SQL] update from and left join

2007-04-11 Thread Tomasz Myrta
Hello I have a query: update A set... from B left join C on (C.col1=B.col1 and C.col2=A.col2) where ... which gives me an error: ERROR: invalid reference to FROM-clause entry for table "A" HINT: There is an entry for table "A", but it cannot be referenced from this part of the query. I fo

Re: [SQL] Update from join

2006-07-07 Thread Michael Glaesemann
On Jul 7, 2006, at 6:29 , Gary Stainburn wrote: I have two tables, both with stock number and registration number in. The second table always has the correct stock number, the first doesn't. I want to copy the data across where the stock number is missing. The select with join shows the

Re: [SQL] Update from join

2006-07-07 Thread Gary Stainburn
On Friday 07 July 2006 11:29, Gary Stainburn wrote: > I know this is probably a FAQ but Google etc hasn't helped. > > I have two tables, both with stock number and registration number in. > The second table always has the correct stock number, the first doesn't. > > I want to copy the data across w

[SQL] Update from join

2006-07-07 Thread Gary Stainburn
I know this is probably a FAQ but Google etc hasn't helped. I have two tables, both with stock number and registration number in. The second table always has the correct stock number, the first doesn't. I want to copy the data across where the stock number is missing. The select with join shows

Re: [SQL] update from multiple rows

2005-01-25 Thread Franco Bruno Borghesi
updating 40.000 records should take no longer than a couple of minutes. I think you should optimise your query before going any further. You have an inner SELECT sentence that executes before anything. It joins EVERY row in your table (1,000,000+) with at most 3 other rows in the same table, so

Re: [SQL] update from multiple rows

2005-01-25 Thread mrblonde
Thanks a lot.. That is what i searched.. In fact your query is very good for little changes, but i will have to use another method when updating all my rows because the performance is not very good alas. My data set contains something like 4 rows to update in 1+ million records and data_raw

Re: [SQL] update from multiple rows

2005-01-24 Thread franco
I understand data_sys is the average value for the 3 days, from at the (Bday before to the day after. (BThis should do what you want, in one pass. Check the average function in (Bthe subselect. If what you want is to divide by 3 no matter how many (Brecords where found, enable the commented lin

Re: [SQL] update from multiple rows

2005-01-23 Thread Michael Fuhr
On Sun, Jan 23, 2005 at 11:36:11AM +, adam etienne wrote: > In fact the computation is somewhat more complex than an average and the > data set is quite large... I did some test with view & triggers but it's > too slow.. Can you provide any more detail about the algorithm and the number of

Re: [SQL] update from multiple rows

2005-01-23 Thread adam etienne
Thanks for your answer (BIn fact the computation is somewhat more complex than an average and the (Bdata set is quite large... I did some test with view & triggers but it's (Btoo slow.. (BMoreover, sometime i need to do big insertion or update and then other time (Bi need juste little updat

Re: [SQL] update from multiple rows

2005-01-22 Thread Michael Fuhr
On Sat, Jan 22, 2005 at 12:51:20PM +, adam etienne wrote: > > I have some trouble updating a table like this one : > date | data_raw | data_sys > 12-01 | 5 | 4.5 > 13-01 | 6 | 6 > 14-01 | 7 |

[SQL] update from multiple rows

2005-01-22 Thread adam etienne
hi (B I have some trouble updating a table like this one : (B date | data_raw | data_sys (B 12-01 | 5 | 4.5 (B 13-01 | 6 | 6 (B 14-01 | 7 | 8 (B (BI would like to update the 'data_sys' ro

Re: [SQL] UPDATE FROM problem, multiple updates of same row don't seem to work

2004-08-11 Thread Bruno Wolff III
On Wed, Aug 11, 2004 at 20:50:28 -0500, David Stanaway <[EMAIL PROTECTED]> wrote: > > I had thought about that, but this is a simpler case of what I need to > do. The operations for each column in the update are dependent on the > current and new values of each row being merged. > > Currently

Re: [SQL] UPDATE FROM problem, multiple updates of same row don't seem to work

2004-08-11 Thread Bruno Wolff III
On Mon, Aug 09, 2004 at 15:16:29 -0500, David Stanaway <[EMAIL PROTECTED]> wrote: > Here is an example: > > CREATE TABLE tablea( > id int PRIMARY KEY, > flag int > ); > > CREATE TABLE tableb( > aid int REFERENCES tablea(id), > flag int > ); > > INSERT INTO tablea VALUES(1,0); > INSERT INTO

[SQL] UPDATE FROM problem, multiple updates of same row don't seem to work

2004-08-09 Thread David Stanaway
Here is an example: CREATE TABLE tablea( id int PRIMARY KEY, flag int ); CREATE TABLE tableb( aid int REFERENCES tablea(id), flag int ); INSERT INTO tablea VALUES(1,0); INSERT INTO tablea VALUES(2,0); -- Flags for 1st row of tablea - When ORed, should be 7 INSERT INTO tableb VALUES(1,1); IN

Re: [SQL] Update from same table

2004-02-04 Thread Josh Berkus
Jurgen, > UPDATE a.mytable from b.mytable > SET a.mycolumn = b.mycolumn > WHERE a.firstid = some_key > AND b.firstid = some_other_key > AND a.secondaryid = b.secondaryid; Very close, actually; you just need to fix the table alias: UPDATE mytable FRO

[SQL] Update from same table

2004-02-04 Thread Jürgen Cappel
Hello, I want to update columns in a table that match a fixed key from the same column of the same table matching another fixed key. There can be several tuples per key distinguished by a secondary id. Tuples are unique with the combined keys. Maybe a query could look something like this:

Re: [SQL] update from select

2003-10-29 Thread Gary Stainburn
On Wednesday 29 Oct 2003 2:58 pm, Stephan Szabo wrote: > On Wed, 29 Oct 2003, Gary Stainburn wrote: > > Hi folks, > > > > don't know if it's cos of the 17 hours I've just worked (sympathy vote > > please) but I can't get this one worked out > > > > I've got table names with nid as name id field and

Re: [SQL] update from select

2003-10-29 Thread Stephan Szabo
On Wed, 29 Oct 2003, Gary Stainburn wrote: > Hi folks, > > don't know if it's cos of the 17 hours I've just worked (sympathy vote please) > but I can't get this one worked out > > I've got table names with nid as name id field and nallowfollow flag. > I've got a vehicles table with vowner pointing

[SQL] update from select

2003-10-29 Thread Gary Stainburn
Hi folks, don't know if it's cos of the 17 hours I've just worked (sympathy vote please) but I can't get this one worked out I've got table names with nid as name id field and nallowfollow flag. I've got a vehicles table with vowner pointing at nid and a vallowfollow field. How can I update na

[SQL] UPDATE FROM portability

2003-03-24 Thread Andreas Pflug
Updating some rows in tab1 with corresponding values from tab2, pgsql style: UPDATE tab1 SET value=T2.VALUE FROM tab2 T2 WHERE T2.restr=1 AND tab1.key=T2.key<< The same for MSSQL: UPDATE tab1 SET value=T2.VALUE FROM tab1 T1 JOIN tab2 T2

[SQL] update from another table

2001-06-12 Thread ivan
dear sir, i would like to know how can i update a table with columns from another table and adding a new column with a secuence, i have try update table set column = (select column from table2), .., set column=secuence.. is it right? thanks ivan ---(end of