X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2EF199DD43A for ; Tue, 29 Nov 2005 12:02:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00605-06 for ; Tue, 29 Nov 2005 12:02:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by postgresql.org (Postfix) with ESMTP id B0A2B9DD43B for ; Tue, 29 Nov 2005 12:02:28 -0400 (AST) Received: from gw7.hlebprom.ru (unknown [62.148.250.13]) by svr2.postgresql.org (Postfix) with ESMTP id 56A1EF0BC3 for ; Tue, 29 Nov 2005 16:02:24 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by gw7.hlebprom.ru (Postfix) with ESMTP id D5C43AB173 for ; Tue, 29 Nov 2005 21:02:12 +0500 (YEKT) Received: from gw7.hlebprom.ru ([127.0.0.1]) by localhost (gw7.hlebprom.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 09352-03 for ; Tue, 29 Nov 2005 21:02:09 +0500 (YEKT) Received: from [10.0.0.2] (unknown [212.57.174.2]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by gw7.hlebprom.ru (Postfix) with ESMTP for ; Tue, 29 Nov 2005 21:02:09 +0500 (YEKT) Date: Tue, 29 Nov 2005 21:01:56 +0500 From: engineer@hlebprom.ru X-Mailer: The Bat! (v3.0) Professional Reply-To: engineer@hlebprom.ru X-Priority: 3 (Normal) Message-ID: <902550887.20051129210156@hlebprom.ru> To: pgsql-sql@postgresql.org Subject: 'AS' in 'DELETE/UPDATE' MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hlebprom.ru X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.882 required=5 tests=[AWL=-0.000, NO_REAL_NAME=0.55, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.882 X-Spam-Level: * X-Archive-Number: 200511/275 X-Sequence-Number: 23526 Hi. Maybe I miss something but I can't use 'AS' with 'DELETE' (7.4.3) Example: db=# SELECT * FROM temp1 ; host_id | user_id | raw | uniq ---------+---------+-----+------ 2 | 1 | 125 | 85 2 | 2 | 100 | 50 (2 rows) And there is temp2 just like temp1. db=# DELETE FROM temp1 AS t1 WHERE EXISTS (SELECT 1 FROM temp2 AS t2 WHERE t2.host_id = t1.host_id AND t2.user_id = t1.user_id); ERROR: syntax error at or near "AS" at character 19 but db=# DELETE FROM temp1 WHERE EXISTS (SELECT 1 FROM temp2 AS t2 WHERE t2.host_id = temp1.host_id AND t2.user_id = temp1.user_id); DELETE 1 db=# SELECT * FROM temp1 ; host_id | user_id | raw | uniq ---------+---------+-----+------ 2 | 1 | 125 | 85 (1 row) It make me supply full name of table... Another example with UPDATE db=# UPDATE referer_total AS ref SET ref.raw = ref.raw + u.raw, ref.uniq = ref.uniq + u.uniq FROM temp1 AS u WHERE u.user_id = ref.user_id AND ref.referer = u.referer; ERROR: syntax error at or near "AS" at character 22 db=# UPDATE referer_total SET db-# referer_total.raw = referer_total.raw + u.raw, db-# referer_total.uniq = referer_total.uniq + u.uniq db-# FROM temp1 AS u WHERE u.user_id = referer_total.user_id db-# AND referer_total.referer = u.referer; ERROR: syntax error at or near "." at character 46 So it make me rename temp1's "raw" to something else ("r"), "uniq" too; and 'AS' not possible too. And finally, working version: UPDATE referer_total SET raw = raw + r, uniq = uniq + u FROM temp1 AS u WHERE u.user_id = referer_total.user_id AND referer_total.referer = u.referer; It looks strange, are there any limitations or something else that make it not possible to use 'AS' in 'DELETE' and 'UPDATE'? Of course with described workarounds I can eliminate that problems, but I want to know is it so in 8.x? Or why, if it right behaviour? -- engineer