pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed'AS' in 'DELETE/UPDATE'
3+ messages / 3 participants
[nested] [flat]
* 'AS' in 'DELETE/UPDATE'
@ 2005-11-29 16:01 engineer@hlebprom.ru
0 siblings, 2 replies; 3+ messages in thread
From: engineer@hlebprom.ru @ 2005-11-29 16:01 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: 'AS' in 'DELETE/UPDATE'
@ 2005-11-29 16:13 Bruce Momjian <pgman@candle.pha.pa.us>
parent: engineer@hlebprom.ru
1 sibling, 0 replies; 3+ messages in thread
From: Bruce Momjian @ 2005-11-29 16:13 UTC (permalink / raw)
To: engineer@hlebprom.ru; +Cc: pgsql-sql
TODO has:
o Allow an alias to be provided for the target table in
UPDATE/DELETE
This is not SQL-spec but many DBMSs allow it.
so we want to add this capability some day.
---------------------------------------------------------------------------
engineer@hlebprom.ru wrote:
> 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: 'AS' in 'DELETE/UPDATE'
@ 2005-11-29 16:14 Jaime Casanova <systemguards@gmail.com>
parent: engineer@hlebprom.ru
1 sibling, 0 replies; 3+ messages in thread
From: Jaime Casanova @ 2005-11-29 16:14 UTC (permalink / raw)
To: engineer@hlebprom.ru; +Cc: pgsql-sql
> 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
>
--- extracted from TODO ---
o Allow an alias to be provided for the target table in UPDATE/DELETE
This is not SQL-spec but many DBMSs allow it.
--- end extracting ---
--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-11-29 16:14 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-29 16:01 'AS' in 'DELETE/UPDATE' engineer@hlebprom.ru
2005-11-29 16:13 ` Bruce Momjian <pgman@candle.pha.pa.us>
2005-11-29 16:14 ` Jaime Casanova <systemguards@gmail.com>
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