pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedquestion about visibilty while updating multiple rows .
3+ messages / 2 participants
[nested] [flat]
* question about visibilty while updating multiple rows .
@ 2003-04-09 07:17 Rajesh Kumar Mallah <mallah@trade-india.com>
0 siblings, 1 reply; 3+ messages in thread
From: Rajesh Kumar Mallah @ 2003-04-09 07:17 UTC (permalink / raw)
To: pgsql-sql
Hi,
If an update statement is affecting multiple rows of a table X ,
Does a subselect (selecting from X only) inside EXISTS part of outer query
able to see the changes when rows are being updated one by one by outer query?
for example consider following set of data rows:
+------------+-----------------------+------+----------+----------------------------------+
| profile_id | co_name | size | deletion | md5 |
+------------+-----------------------+------+----------+----------------------------------+
| 212161 | ATITH FIBRE PVT. LTD. | FL | t | edc462794427724b7d132e3b1387d69f |
| 212159 | ATITH FIBRE PVT. LTD. | 1HS | f | edc462794427724b7d132e3b1387d69f |
| 216225 | ATITH FIBRE PVT. LTD. | 1HS | f | edc462794427724b7d132e3b1387d69f |
| 216226 | ATITH FIBRE PVT. LTD. | 1HS | f | edc462794427724b7d132e3b1387d69f |
+------------+-----------------------+------+----------+----------------------------------+
begin work;
UPDATE eyp_profiles_table SET
deletion=true
WHERE
co_name='ATITH FIBRE PVT. LTD.' AND
deletion is false and
EXISTS (select * from eyp_profiles_table a where a.md5=eyp_profiles_table.md5 and
a.deletion is false and a.profile_id <> eyp_profiles_table.profile_id) ;
my original problem is to update in such a way that i get below finally (observer the deletion column)
+------------+-----------------------+------+----------+----------------------------------+
| profile_id | co_name | size | deletion | md5 |
+------------+-----------------------+------+----------+----------------------------------+
| 212161 | ATITH FIBRE PVT. LTD. | FL | t | edc462794427724b7d132e3b1387d69f |
| 212159 | ATITH FIBRE PVT. LTD. | 1HS | t | edc462794427724b7d132e3b1387d69f |
| 216225 | ATITH FIBRE PVT. LTD. | 1HS | t | edc462794427724b7d132e3b1387d69f |
| 216226 | ATITH FIBRE PVT. LTD. | 1HS | f | edc462794427724b7d132e3b1387d69f |
+------------+-----------------------+------+----------+----------------------------------+
so that only one entry per md5 record exists.
Regds
mallah.
--
Rajesh Kumar Mallah,
Project Manager (Development)
Infocom Network Limited, New Delhi
phone: +91(11)6152172 (221) (L) ,9811255597 (M)
Visit http://www.trade-india.com ,
India's Leading B2B eMarketplace.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: question about visibilty while updating multiple rows .
@ 2003-04-09 15:12 Tom Lane <tgl@sss.pgh.pa.us>
parent: Rajesh Kumar Mallah <mallah@trade-india.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2003-04-09 15:12 UTC (permalink / raw)
To: Rajesh Kumar Mallah <mallah@trade-india.com>; +Cc: pgsql-sql
> If an update statement is affecting multiple rows of a table X ,
> Does a subselect (selecting from X only) inside EXISTS part of outer query
> able to see the changes when rows are being updated one by one by outer query?
No, because it's part of the same query.
I believe though that a user-defined function called from the update
query would see the changes made so far. So possibly you can fix your
problem by pushing the EXISTS down into a SQL or plpgsql function.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: question about visibilty while updating multiple rows .
@ 2003-04-10 04:41 Rajesh Kumar Mallah <mallah@trade-india.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Rajesh Kumar Mallah @ 2003-04-10 04:41 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
On Wednesday 09 Apr 2003 8:42 pm, Tom Lane wrote:
> > If an update statement is affecting multiple rows of a table X ,
> > Does a subselect (selecting from X only) inside EXISTS part of outer
> > query able to see the changes when rows are being updated one by one by
> > outer query?
>
> No, because it's part of the same query.
>
> I believe though that a user-defined function called from the update
> query would see the changes made so far. So possibly you can fix your
> problem by pushing the EXISTS down into a SQL or plpgsql function.
Thanks for the explanation and suggestion Tom,
I did it however by using intermediate tables and distinct on().
Regds
Mallah.
>
> regards, tom lane
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Rajesh Kumar Mallah,
Project Manager (Development)
Infocom Network Limited, New Delhi
phone: +91(11)6152172 (221) (L) ,9811255597 (M)
Visit http://www.trade-india.com ,
India's Leading B2B eMarketplace.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-04-10 04:41 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-04-09 07:17 question about visibilty while updating multiple rows . Rajesh Kumar Mallah <mallah@trade-india.com>
2003-04-09 15:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-04-10 04:41 ` Rajesh Kumar Mallah <mallah@trade-india.com>
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