pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
UPDATE table SET col = (SELECT ...)
3+ messages / 3 participants
[nested] [flat]

* UPDATE table SET col = (SELECT ...)
@ 1998-12-30 17:01 Eric Marsden <emarsden@mail.dotcom.fr>
  0 siblings, 0 replies; 3+ messages in thread

From: Eric Marsden @ 1998-12-30 17:01 UTC (permalink / raw)
  To: pgsql-sql

Hello,

If I understand the SQL references I have read, UPDATEs are allowed to
pull data from SELECT statements, something like

  UPDATE table SET col1 = (SELECT val1 FROM table WHERE id = 34),
               SET col2 = (SELECT val2 FROM table WHERE id = 34)
         WHERE id = 35;

However, the PostgreSQL parser chokes on the 'SELECT'. The
documentation says

  UPDATE table SET column = expression [, ...]
      [ FROM fromlist ]
      [ WHERE condition ]         

  expression = A valid expression or value to assign to column.


I don't know exactly how to interpret `valid expression'.
      
-- 
Eric Marsden
emarsden @ mail.dotcom.fr
It's elephants all the way down



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* UPDATE table SET col = (SELECT ...)
@ 2003-06-25 09:00 Vangelis-Maria Tougia <tougias@cytanet.com.cy>
  2003-06-26 21:11 ` Re: UPDATE table SET col = (SELECT ...) Ian Barwick <barwick@gmx.net>
  0 siblings, 1 reply; 3+ messages in thread

From: Vangelis-Maria Tougia @ 2003-06-25 09:00 UTC (permalink / raw)
  To: pgsql-sql

Hi,
I found follwing email sent to you in internet.
I am interested in same issue myself.
Did you finally found out any more information about how to Update a column
of a table by selecting value from another table?


Hello,

If I understand the SQL references I have read, UPDATEs are allowed to
pull data from SELECT statements, something like

  UPDATE table SET col1 = (SELECT val1 FROM table WHERE id = 34),
               SET col2 = (SELECT val2 FROM table WHERE id = 34)
         WHERE id = 35;

However, the PostgreSQL parser chokes on the 'SELECT'. The
documentation says

  UPDATE table SET column = expression [, ...]
      [ FROM fromlist ]
      [ WHERE condition ]

  expression = A valid expression or value to assign to column.


I don't know exactly how to interpret `valid expression'.

--
Eric Marsden
emarsden @ mail.dotcom.fr
It's elephants all the way down

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: UPDATE table SET col = (SELECT ...)
  2003-06-25 09:00 UPDATE table SET col = (SELECT ...) Vangelis-Maria Tougia <tougias@cytanet.com.cy>
@ 2003-06-26 21:11 ` Ian Barwick <barwick@gmx.net>
  0 siblings, 0 replies; 3+ messages in thread

From: Ian Barwick @ 2003-06-26 21:11 UTC (permalink / raw)
  To: Vangelis-Maria Tougia <tougias@cytanet.com.cy>; pgsql-sql

On Wednesday 25 June 2003 11:00, Vangelis-Maria Tougia wrote:
> Hi,
> I found follwing email sent to you in internet.
> I am interested in same issue myself.
> Did you finally found out any more information about how to Update a column
> of a table by selecting value from another table?

Not sure if this has been answered previously, but here goes:

> Hello,
>
> If I understand the SQL references I have read, UPDATEs are allowed to
> pull data from SELECT statements, something like
>
>   UPDATE table SET col1 = (SELECT val1 FROM table WHERE id = 34),
>                SET col2 = (SELECT val2 FROM table WHERE id = 34)
                 ^^^
>          WHERE id = 35;

The second "SET" is not necessary or allowed and is causing the update to
fail.


Ian Barwick
barwick@gmx.net





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2003-06-26 21:11 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-12-30 17:01 UPDATE table SET col = (SELECT ...) Eric Marsden <emarsden@mail.dotcom.fr>
2003-06-25 09:00 UPDATE table SET col = (SELECT ...) Vangelis-Maria Tougia <tougias@cytanet.com.cy>
2003-06-26 21:11 ` Ian Barwick <barwick@gmx.net>

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