Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A6AD51337B99 for ; Thu, 16 Dec 2010 15:59:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 24353-06 for ; Thu, 16 Dec 2010 19:59:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpcorp.com (smtpcorp.com [67.192.120.76]) by mail.postgresql.org (Postfix) with ESMTP id BF5E41337B98 for ; Thu, 16 Dec 2010 15:59:04 -0400 (AST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpcorp.com; s=main; h=References:Message-ID:Date:Subject:From:To; bh=A1SinAANjB0q+ZkRfmowbFUh/1F19Dipew9lU2BMXug=; b=KsYwLHxYchO00EiGXYh1YqCZHZzDDqC5FioXQbUaB87Kl5i66OfEUhfmVBpZ8jH4gXddrYeo/vO7PK5Vf5Oq01pFJLeyFPyPzbsafOYnIRiO8A0L7qJKVT66/Tt7sN92; Received: from ip-118-90-129-120.xdsl.xnet.co.nz ([118.90.129.120] helo=gonzo) by smtpcorp.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.70) id 1PTJyg-0005us-DD; mid 144 for pgsql-sql@postgresql.org; Thu, 16 Dec 2010 19:59:02 +0000 Received: from news by gonzo with local (Exim 4.72) (envelope-from ) id 1PTJyU-0003il-Kr for pgsql-sql@postgresql.org; Fri, 17 Dec 2010 08:58:50 +1300 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: UPDATE in a specific order Date: 16 Dec 2010 19:58:50 GMT Organization: Dis (not Dat) Organisation Lines: 30 Message-ID: References: <4D0A28F0.3020205@planit.com.br> NNTP-Posting-Host: localhost X-Trace: reversiblemaps.ath.cx 1292529530 14305 127.0.0.1 (16 Dec 2010 19:58:50 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-18 (Linux) X-Smtpcorp-Track: 18584165.1.57647584 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201012/83 X-Sequence-Number: 34919 > I need to make update of table1 with data on table2 in the order of id > of table2 that looks like EAV. is it? > I=B4m trying to do an update like this: that's not going to work. perhaps you can rewrite the from part to only return one row for every table1_fk, this one row will combine several rows from table2 > The "FROM ( SELECT * FROM table2 ORDER BY id ) tHist" is a try to > force a specific order on table2 to update table1 > but this isn=B4t working. will only work if the optimiser picks index join on table 1 > There are some way to do this with a UPDATE statement ? to do it with an update statement you need no more than one rows in the from for each row in the target. easiest non update statement approach is probably to use a plpgsql function with a loop. basically you need to find another way to do it.