Re: request for sql3 compliance for the update command

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Hannu Krosing <hannu(at)tm(dot)ee>
Cc: Dave Cramer <dave(at)fastcrypt(dot)com>, scott(dot)marlowe(at)ihs(dot)com, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: request for sql3 compliance for the update command
Date: 2003-03-19 14:36:50
Message-ID: 200303191436.h2JEaoJ21825@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


I wasn't sure it made logical sense to allow correlated subqueries in
FROM because the FROM is processed before the WHERE.

---------------------------------------------------------------------------

Hannu Krosing wrote:
> Bruce Momjian kirjutas E, 17.03.2003 kell 20:49:
> > With no one replying on how to do correlated subqueries in FROM for
> > UPDATE,
>
> Correlated subqueries not working in FROM cluse of UPDATE is IMHO a bug,
> so the way to do correlated subqueries in FROM for UPDATE would be to
> fix this bug ;)
>
> All common sense tells me that if I can update set col1=col2 and *not*
> get the value from the first col2 to all col1's then the same should be
> true for this
>
> hannu=# creatre table updtarget(
> hannu(# id int, val text);
> ERROR: parser: parse error at or near "creatre" at character 1
> hannu=# create table updtarget(id int, val text);
> CREATE TABLE
> hannu=# create table updsource(id int, val text);
> CREATE TABLE
> hannu=# insert into updtarget(id) values (1);
> INSERT 16995 1
> hannu=# insert into updtarget(id) values (2);
> INSERT 16996 1
> hannu=# insert into updsource(id,val) values (1,'one');
> INSERT 16997 1
> hannu=# insert into updsource(id,val) values (2,'two');
> INSERT 16998 1
> hannu=# update updtarget set val = src.val
> hannu-# from (select s.val from updsource s
> hannu-# where s.id=updtarget.id) as src
> hannu-# ;
> NOTICE: Adding missing FROM-clause entry in subquery for table
> "updtarget"
> UPDATE 2
> hannu=# select * from updtarget;
> id | val
> ----+-----
> 1 | one
> 2 | one
> (2 rows)
>
> there should be no need to add "missing FROM-clause entry" and the
> result *should* be:
>
> hannu=# select * from updtarget;
> id | val
> ----+-----
> 1 | one
> 2 | two
> (2 rows)
>
> --------------------
> Hannu
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-03-19 14:46:00 Re: request for sql3 compliance for the update command
Previous Message Bruce Momjian 2003-03-19 14:34:27 Re: Win32 native port