update more than 1 table (mysql to postgres)

From: "treeml" <treeml(at)itree(dot)org>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: update more than 1 table (mysql to postgres)
Date: 2004-01-30 08:19:32
Message-ID: AOEMLAIJIPAIPHJEAHBOCEHJDPAA.treeml@itree.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I am migrating from MySQL to Postagres. I have problem with postgres
updating 2 tables with one statement.

In MySQL I can update 2 tables (parent, child) with a statement like this

UPDATE parent LEFT JOIN child ON parent.pid = child.foreign_key SET
parent.field1 = 'company',
child.field2 = 'john'
WHERE child.pid = 7

Or I can also do
UPDATE parent, child SET parent.field1 = 'company', child.field2 = 'john'
WHERE
parent.pid = child.foreign_key
AND child.pid = 7

But I couldn't do that in Postgres,
Only one table is allowed in an update statement. I tried to create a view,
and updating the view, but that was not allowed. I could do 2 SQL
updates, but I am sure there is a better way to do this. Anyone have any
idea. Appreciated.

Tree

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2004-01-30 09:00:44 Re: java.lang.StringIndexOutOfBoundsException: String index
Previous Message cheater cheater 2004-01-30 07:41:42 locking problem