WG: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL

Поиск
Список
Период
Сортировка
От Gau, Hans-Jürgen
Тема WG: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL
Дата
Msg-id 670F563845D6B34189933C9C7322B4872C089C@LV-MX-00002-V02.LV.ads.niedersachsen.de
обсуждение исходный текст
Ответы Re: WG: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL  (nha <lyondif02@free.fr>)
Список pgsql-sql
Sorry, it's a lapse by copying and simplification the original version. that
is correct:

UPDATE table1 t1 SET (t1.id) =     (SELECT t3.id FROM table2 t2,table3 t3, table1 t1     WHERE t3.field = t2.field
  AND t2.id = t1.id         AND t1.id <> t3.id) WHERE     (SELECT t3.id FROM table2 t2,table3 t3, table1 t1     WHERE
t3.field= t2.field         AND t2.id = t1.id         AND t1.id <> t3.id) IS NOT NULL;  


or in very simplified form:

UPDATE table t1SET (t1.id)=(SELECT expression)WHERE     (SELECT expression) IS NOT NULL;


The SELECT expressions are identical.

this syntax is allowed on postgresql?

the solution brought by Daryl Richter has no effect.
Regards, Hans

-----Ursprüngliche Nachricht-----
Von: nha [mailto:lyondif02@free.fr]
Gesendet: Dienstag, 28. Juli 2009 23:11
An: Gau, Hans-Jürgen
Cc: PgSQL-sql
Betreff: Re: [SQL] sql-porting-problem oracle to postgresql with UPDATE/IS
NOT NULL

Hello,

Le 28/07/09 14:25, Daryl Richter a écrit :
>
> On Jul 28, 2009, at 5:58 AM, Gau, Hans-Jürgen wrote:
>
>> hello list,
>> i have some problems with an sql-statement which runs on oracle but
>> not on postgresql (i want update only if result of SELECT is not
>> empty, the SELECT-queries are identical):
>>
>> UPDATE table1 t1
>>         SET (t1.id) =
>>                 (SELECT h.id FROM table2 t2,table3 t3, table1 t1
>>                 WHERE t3.field = t2.field
>>                         AND t2.id = t1.id
>>                         AND t1.id <> t3.id)
>>         WHERE
>>                 (SELECT h.id FROM table2 t2,table3 t3, table1 t1
>>                         WHERE t3.field = t2.field
>>                                 AND t2.id = t1.id
>>                                 AND t1.id <> t3.id) IS NOT NULL;
>>
> Try this:
>
> UPDATE table1 t1 [...]
>         WHERE
>             EXISTS (SELECT 1 FROM table2 t2,table3 t3, table1 t1
>                         WHERE t3.field = t2.field
>                                 AND t2.id = t1.id
>                                 AND t1.id <> t3.id
>
>                 AND h.id IS NOT NULL);
>

Beyond the solution brought by Daryl Richter, it seems that "h" is an
unbound alias in the original (and also in the suggested) query. Some
clarification would be helpful for further investigation.

Regards.

--
nha / Lyon / France.



В списке pgsql-sql по дате отправления:

Предыдущее
От: Tim Landscheidt
Дата:
Сообщение: Re: Tweak sql result set... ?
Следующее
От: nha
Дата:
Сообщение: Re: WG: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL