SQL - update table problem...

Started by rikiover 19 years ago4 messagesgeneral
Jump to latest
#1riki
riki_fox@hotmail.com

Hi,

i'm trying to make update on multiple tables but don't know how.
is something like this posible with postgresql?

update table1
join table2 on (table1.id=table2.t1)
join table3 on (table2.id=table3.t2)
set table1.name='test', table2.sum=table1.x+table2.y,
table3.cell='123456789'
where table1.id=6

i know that this syntax is not supported with postgres but i tried to
rewrite the code using this synopsis:

UPDATE [ ONLY ] table SET column = { expression | DEFAULT } [, ...]
[ FROM fromlist ]
[ WHERE condition ]

i failed again.
updating multiple tables, can it be done?

thanks for help

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

#2Noname
Matthias.Pitzl@izb.de
In reply to: riki (#1)
Re: SQL - update table problem...

Hi!

According to the synopsis of UPDATE you just can update one table at a time.
Just use more UPDATE commands inside a transaction.

-- Matthias

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Marko Rihtar
Sent: Monday, November 13, 2006 2:21 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] SQL - update table problem...

Hi,

i'm trying to make update on multiple tables but don't know how.
is something like this posible with postgresql?

update table1
join table2 on (table1.id=table2.t1)
join table3 on (table2.id=table3.t2)
set table1.name='test', table2.sum=table1.x+table2.y,
table3.cell='123456789'
where table1.id=6

i know that this syntax is not supported with postgres but i tried to
rewrite the code using this synopsis:

UPDATE [ ONLY ] table SET column = { expression | DEFAULT } [, ...]
[ FROM fromlist ]
[ WHERE condition ]

i failed again.
updating multiple tables, can it be done?

thanks for help

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

---------------------------(end of
broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org/

#3Richard Huxton
dev@archonet.com
In reply to: riki (#1)
Re: SQL - update table problem...

Marko Rihtar wrote:

Hi,

i'm trying to make update on multiple tables but don't know how.
is something like this posible with postgresql?

update table1
join table2 on (table1.id=table2.t1)
join table3 on (table2.id=table3.t2)
set table1.name='test', table2.sum=table1.x+table2.y,
table3.cell='123456789'
where table1.id=6

I don't know of an SQL variant to handle this case. Usually people are
trying to update a single table based on joining to several others.

In your case you'll have to issue three update statements wrapped in a
transaction.

--
Richard Huxton
Archonet Ltd

#4Shoaib Mir
shoaibmir@gmail.com
In reply to: Richard Huxton (#3)
Re: SQL - update table problem...

You can try using a combination of a view and rule attached to it for
achieving the same...

Thanks,
-------
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

Show quoted text

On 11/13/06, Richard Huxton <dev@archonet.com> wrote:

Marko Rihtar wrote:

Hi,

i'm trying to make update on multiple tables but don't know how.
is something like this posible with postgresql?

update table1
join table2 on (table1.id=table2.t1)
join table3 on (table2.id=table3.t2)
set table1.name='test', table2.sum=table1.x+table2.y,
table3.cell='123456789'
where table1.id=6

I don't know of an SQL variant to handle this case. Usually people are
trying to update a single table based on joining to several others.

In your case you'll have to issue three update statements wrapped in a
transaction.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings