Re: [SQL] select in update - Mailing list pgsql-sql

From Engard Ferenc
Subject Re: [SQL] select in update
Date
Msg-id Pine.LNX.3.96.981124104050.6087C-100000@Pons.sote.hu
Whole thread Raw
In response to Re: [SQL] select in update  (Herouth Maoz <herouth@oumail.openu.ac.il>)
Responses Re: [SQL] select in update  (Herouth Maoz <herouth@oumail.openu.ac.il>)
List pgsql-sql
On Tue, 24 Nov 1998, Herouth Maoz wrote:

>The long-standing syntax for this in PostgreSQL is:
>
>UPDATE shorttest2
>SET b=t1.b
>FROM shorttest t1
>WHERE t1.a=1;
>
>Please, look up the manpages for the command you want to invoke, or \h it.
>You may discover syntax options that cover what you need. I have PostgreSQL

Thx for the help! Anyway, I have read the docs, but since there is no
example there, and I didn't know this syntax (and maybe my english is not
so good), I couldn't figure out what is this strange FROM clausule... :))

Well, then a little bit complex problem:
two tables: A (var), B (var1,var2). I would like to replace the A.var
if it exists in B.var2 with B.var1. Is it good?

UPDATE a
SET a.var=b.var1
FROM b                <-- or maybe I need to put 'a' here too?
WHERE a.var=b.var2;

I don't need to tell that there are rows which cannot find in B? (In
this case it shouldn't change.)

I feel that I need to write two different WHERE-s: one for the subquery
(which then results 1 row), and one for the UPDATE, to tell where to
put that value. I solved this until now with a 'c' prg.

Thanks again and bye:
Circum

 __  @
/  \    _   _                                           Engard Ferenc
l    | ( \ /  | | (\/)                      mailto:s-fery@kkt.sote.hu
\__/ | |   \_ \_/ I  I                    http://pons.sote.hu/~s-fery



pgsql-sql by date:

Previous
From: Herouth Maoz
Date:
Subject: Re: [SQL] MINUS and slow 'not in'
Next
From: Vadim Mikheev
Date:
Subject: Re: [SQL] cursor and update + view