X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id F129ED1B202 for ; Mon, 10 May 2004 18:11:34 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 12850-02 for ; Mon, 10 May 2004 18:11:16 -0300 (ADT) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by svr1.postgresql.org (Postfix) with ESMTP id 64AF8D1B17C for ; Mon, 10 May 2004 18:11:12 -0300 (ADT) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1BNI3N-00048a-00 for ; Mon, 10 May 2004 23:11:13 +0200 Received: from host-216-153-204-229.buf.choiceone.net ([216.153.204.229]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 May 2004 23:11:13 +0200 Received: from jtk by host-216-153-204-229.buf.choiceone.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 May 2004 23:11:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Jeff Kowalczyk Subject: update table where rows are selected by inner join? Date: Mon, 10 May 2004 17:13:44 -0500 Lines: 36 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: host-216-153-204-229.buf.choiceone.net User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.5 tagged_above=0.0 required=5.0 tests=FORGED_YAHOO_RCVD X-Spam-Level: X-Archive-Number: 200405/89 X-Sequence-Number: 17803 I have two tables orders and customerpaymentnote, which keep denormalized columns of the status in rows related by orderid. The column duplication is intentional, to ease end-user ad-hoc queries. I don't understand the UPDATE FROM clause at: http://www.postgresql.org/docs/7.4/static/sql-update.html I have a query working (slowly) in MS Access with the pgodbc driver, but I need to know the Postgres version of the SQL. Working (but slow) MS Access version: UPDATE orders INNER JOIN customerpaymentnote ON orders.orderid=customerpaymentnote.orderid SET orders.customerdatetimepaid = customerpaymentnote.customerdatetimepaid, orders.customerchargeaspaid = customerpaymentnote.customerchargeaspaid, orders.customerchargestatus = "Payment-Recieved", orders.orderworkflowbillingstateid = "Payment-Recieved"; Postgres translation, which does not yet work: UPDATE orders SET customerdatetimepaid = customerpaymentnote.customerdatetimepaid, customerchargeaspaid = customerpaymentnote.customerchargeaspaid, customerchargestatus = "Payment-Recieved", orderworkflowbillingstateid = "Payment-Recieved" FROM orders INNER JOIN customerpaymentnote ON orders.orderid=customerpaymentnote.orderid Query result with 0 rows will be returned. ERROR: table name "orders" specified more than once Can anyone suggest a proper translation. I'm open to other query strategies, if an IN(...) statement or something else will speed up this slow query. Thanks.