pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: engineer@hlebprom.ru
To: pgsql-sql@postgresql.org
Subject: 'AS' in 'DELETE/UPDATE'
Date: Tue, 29 Nov 2005 21:01:56 +0500
Message-ID: <902550887.20051129210156@hlebprom.ru> (raw)

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




view thread (3+ messages)  latest in thread

Message-ID: <902550887.20051129210156@hlebprom.ru>
Permalink:  ../902550887.20051129210156@hlebprom.ru/
Also on:    postgresql.org/message-id/902550887.20051129210156@hlebprom.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: engineer@hlebprom.ru
  Subject: Re: 'AS' in 'DELETE/UPDATE'
  In-Reply-To: <902550887.20051129210156@hlebprom.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox