pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedsql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL
4+ messages / 3 participants
[nested] [flat]
* sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL
@ 2009-07-28 09:58 "Gau, Hans-Jürgen" <Hans-Juergen.Gau@LGN.Niedersachsen.de>
0 siblings, 1 reply; 4+ messages in thread
From: "Gau, Hans-Jürgen" @ 2009-07-28 09:58 UTC (permalink / raw)
To: pgsql-sql
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;
thanks, hans
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL
@ 2009-07-28 12:25 Daryl Richter <ngzax@comcast.net>
parent: "Gau, Hans-Jürgen" <Hans-Juergen.Gau@LGN.Niedersachsen.de>
0 siblings, 1 reply; 4+ messages in thread
From: Daryl Richter @ 2009-07-28 12:25 UTC (permalink / raw)
To: "Gau, Hans-Jürgen" <Hans-Juergen.Gau@LGN.Niedersachsen.de>; +Cc: pgsql-sql
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
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
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);
>
>
> thanks, hans
>
>
--
Daryl
http://itsallsemantics.com
""Everyone thinks of changing the world, but no one thinks of changing
himself."
- Leo Tolstoy
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL
@ 2009-07-28 21:10 nha <lyondif02@free.fr>
parent: Daryl Richter <ngzax@comcast.net>
0 siblings, 1 reply; 4+ messages in thread
From: nha @ 2009-07-28 21:10 UTC (permalink / raw)
To: "Gau, Hans-Jürgen" <Hans-Juergen.Gau@LGN.Niedersachsen.de>; +Cc: pgsql-sql
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.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL
@ 2009-07-29 13:44 Daryl Richter <ngzax@comcast.net>
parent: nha <lyondif02@free.fr>
0 siblings, 0 replies; 4+ messages in thread
From: Daryl Richter @ 2009-07-29 13:44 UTC (permalink / raw)
To: nha <lyondif02@free.fr>; +Cc: "Gau, Hans-Jürgen" <Hans-Juergen.Gau@LGN.Niedersachsen.de>; pgsql-sql
On Jul 28, 2009, at 5:10 PM, nha wrote:
> 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.
Ahh, you're right. I didn't even notice that, just reformatted the
OPs query.
>
> Regards.
>
> --
> nha / Lyon / France.
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
--
Daryl
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2009-07-29 13:44 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-07-28 09:58 sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL "Gau, Hans-Jürgen" <Hans-Juergen.Gau@LGN.Niedersachsen.de>
2009-07-28 12:25 ` Daryl Richter <ngzax@comcast.net>
2009-07-28 21:10 ` nha <lyondif02@free.fr>
2009-07-29 13:44 ` Daryl Richter <ngzax@comcast.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