From moizpostgres@gmail.com Wed Jan 17 11:20:37 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 5C8099FB1D8 for ; Wed, 17 Jan 2007 07:20:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 96721-01 for ; Wed, 17 Jan 2007 07:20:17 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by postgresql.org (Postfix) with ESMTP id 74D8E9FA468 for ; Wed, 17 Jan 2007 07:20:21 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so1916907ugf for ; Wed, 17 Jan 2007 03:20:20 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=kK2wX+/v0KXHX6Fw4Tl8Hfam6av5AK3RxKl1tdqJ4PCagDMmQZuln8OkL7ewwZtX+JiKj/M0jJoJFa89c67f5D/41qCwf3gcfDawmG97zWHUGDmBhIGyuyOZm/3rvdR+S3ramZdx5R3xJvq16wQ20ZcofW7B6wbsc0GOO4U1/U4= Received: by 10.66.216.20 with SMTP id o20mr9280206ugg.1169032818904; Wed, 17 Jan 2007 03:20:18 -0800 (PST) Received: by 10.67.26.17 with HTTP; Wed, 17 Jan 2007 03:20:18 -0800 (PST) Message-ID: <82e1a9bd0701170320j14d4ebdagd66d8c9f095b0192@mail.gmail.com> Date: Wed, 17 Jan 2007 16:50:18 +0530 From: "Moiz Kothari" To: pgsql-sql@postgresql.org Subject: Update query by joining multiple tables. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_103532_3679585.1169032818860" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/65 X-Sequence-Number: 27217 ------=_Part_103532_3679585.1169032818860 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Guys, on page this http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not specified if a join can be done between multiple tables to update a table, i tried and it worked just fine for me. Something like this : Infact update can work between multiple tables to... do something like : UPDATE employees SET sales_count = a.sales_count FROM accounts as a WHERE a.name = 'Acme Corporation' AND employees.id = a.sales_person; considering sales_count as a column in accounts table. Regards, Moiz ------=_Part_103532_3679585.1169032818860 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Guys,

on page this

http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not specified if a join can be done between multiple tables to update a table, i tried and it worked just fine for me. Something like this :

Infact update can work between multiple tables to... do something like :

UPDATE employees SET sales_count = a.sales_count FROM accounts as a
  WHERE a.name = 'Acme Corporation'
  AND employees.id = a.sales_person;

considering sales_count as a column in accounts table.

Regards,
Moiz


------=_Part_103532_3679585.1169032818860-- From ajs@crankycanuck.ca Wed Jan 17 12:55:39 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 2D2C99FB228 for ; Wed, 17 Jan 2007 08:55:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 28523-03 for ; Wed, 17 Jan 2007 08:55:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from main2.mycybernet.net (main2.mycybernet.net [209.222.63.140]) by postgresql.org (Postfix) with ESMTP id 69BD29FB223 for ; Wed, 17 Jan 2007 08:55:22 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227] helo=phlogiston.dydns.org) by main2.mycybernet.net with esmtp (Exim 4.62) (envelope-from ) id 1H7ATo-0007OY-Ho for pgsql-sql@postgresql.org; Wed, 17 Jan 2007 08:05:28 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id AE33141A2; Wed, 17 Jan 2007 07:55:11 -0500 (EST) Date: Wed, 17 Jan 2007 07:55:11 -0500 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: Update query by joining multiple tables. Message-ID: <20070117125511.GC19527@phlogiston.dyndns.org> References: <82e1a9bd0701170320j14d4ebdagd66d8c9f095b0192@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <82e1a9bd0701170320j14d4ebdagd66d8c9f095b0192@mail.gmail.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/67 X-Sequence-Number: 27219 On Wed, Jan 17, 2007 at 04:50:18PM +0530, Moiz Kothari wrote: > http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not > specified if a join can be done between multiple tables to update a table, i Sure it is: A list of table expressions, allowing columns from other tables to appear in the WHERE condition and the update expressions. a -- Andrew Sullivan | ajs@crankycanuck.ca Users never remark, "Wow, this software may be buggy and hard to use, but at least there is a lot of code underneath." --Damien Katz From shoaibmir@gmail.com Wed Jan 17 15:01:43 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 3E8F29FB1A5 for ; Wed, 17 Jan 2007 11:01:43 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 66001-08 for ; Wed, 17 Jan 2007 11:00:56 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by postgresql.org (Postfix) with ESMTP id B1DC19FB22C for ; Wed, 17 Jan 2007 11:01:01 -0400 (AST) Received: by an-out-0708.google.com with SMTP id c24so1230323ana for ; Wed, 17 Jan 2007 07:01:00 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=DnpDpEEM8HMWeIefForYAbrlwne5oboES7LRX0Bub7LitRHImusrKPSBSkPE2ja54yImNBZSbFEjpqlD2EfQI3zYrjiDJqKy7CWhZV3U/RabwWImbOVwXKd/Et1Ep5O032CFhdIiHtVUJlcKVSaJLFtKHWPSqPS6PiEGDZfDKNU= Received: by 10.65.192.16 with SMTP id u16mr10175063qbp.1169046060351; Wed, 17 Jan 2007 07:01:00 -0800 (PST) Received: by 10.65.188.5 with HTTP; Wed, 17 Jan 2007 07:01:00 -0800 (PST) Message-ID: Date: Wed, 17 Jan 2007 20:01:00 +0500 From: "Shoaib Mir" To: "Andrew Sullivan" Subject: Re: Update query by joining multiple tables. Cc: pgsql-sql@postgresql.org In-Reply-To: <20070117125511.GC19527@phlogiston.dyndns.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_70919_3336007.1169046060224" References: <82e1a9bd0701170320j14d4ebdagd66d8c9f095b0192@mail.gmail.com> <20070117125511.GC19527@phlogiston.dyndns.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/71 X-Sequence-Number: 27223 ------=_Part_70919_3336007.1169046060224 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Might be a view and then a rule attached with that can help you out with doing updates using joins -------------- Shoaib Mir EnterpriseDB (www.enterprisedb.com) On 1/17/07, Andrew Sullivan wrote: > > On Wed, Jan 17, 2007 at 04:50:18PM +0530, Moiz Kothari wrote: > > http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is > not > > specified if a join can be done between multiple tables to update a > table, i > > Sure it is: > > A list of table expressions, allowing columns from other tables to > appear in the WHERE condition and the update expressions. > > a > > -- > Andrew Sullivan | ajs@crankycanuck.ca > Users never remark, "Wow, this software may be buggy and hard > to use, but at least there is a lot of code underneath." > --Damien Katz > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > ------=_Part_70919_3336007.1169046060224 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Might be a view and then a rule attached with that can help you out with doing updates using joins

--------------
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 1/17/07, Andrew Sullivan <ajs@crankycanuck.ca> wrote:
On Wed, Jan 17, 2007 at 04:50:18PM +0530, Moiz Kothari wrote:
> http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not
> specified if a join can be done between multiple tables to update a table, i

Sure it is:

A list of table expressions, allowing columns from other tables to
appear in the WHERE condition and the update expressions.

a

--
Andrew Sullivan  | ajs@crankycanuck.ca
Users never remark, "Wow, this software may be buggy and hard
to use, but at least there is a lot of code underneath."
                --Damien Katz

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

------=_Part_70919_3336007.1169046060224--