pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Order of execution
2+ messages / 2 participants
[nested] [flat]

* Order of execution
@ 2013-05-06 00:04  JORGE MALDONADO <jorgemal1960@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: JORGE MALDONADO @ 2013-05-06 00:04 UTC (permalink / raw)
  To: pgsql-sql

I have an UPDATE query which performs several opertions in one table.

UPDATE table01 SET
field1 = (query1 may contain any field),
field2 = (query1 may contain any field),
field3 = (query1 may contain any field)
WHERE (condition)

query1, query2 and query3 perform a logic to determine which records will
be updated. Does field1 updates first, then  field2 and, lastly, field3? or
What is the order in which updates are executed? If I need fields to be
updated in a certain order, should I use 3 UPDATE commands instead?

Respectfully,
Jorge Maldonado

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Order of execution
@ 2013-05-06 09:07  Jasen Betts <jasen@xnet.co.nz>
  parent: JORGE MALDONADO <jorgemal1960@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jasen Betts @ 2013-05-06 09:07 UTC (permalink / raw)
  To: pgsql-sql

On 2013-05-06, JORGE MALDONADO <jorgemal1960@gmail.com> wrote:
> --089e013d1eb83325e504dc01710d
> Content-Type: text/plain; charset=ISO-8859-1
>
> I have an UPDATE query which performs several opertions in one table.
>
> UPDATE table01 SET
> field1 = (query1 may contain any field),
> field2 = (query1 may contain any field),
> field3 = (query1 may contain any field)
> WHERE (condition)
>
> query1, query2 and query3 perform a logic to determine which records will
> be updated. Does field1 updates first, then  field2 and, lastly, field3?

Updates are one row at a time in an unpredictble order.
this will be wrapped in a transaction so either all will 
updated or none.

testing suggests that in simple cases the expressions are evaluated in
the order the columns appear in the table definition, but I wouldn't
rely on that.

> or What is the order in which updates are executed? If I need fields to be
> updated in a certain order, should I use 3 UPDATE commands instead?

yeah, if "simultaneously" isn't acceptable you'll need to do separate
updates.

-- 
⚂⚃ 100% natural



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2013-05-06 09:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-05-06 00:04 Order of execution JORGE MALDONADO <jorgemal1960@gmail.com>
2013-05-06 09:07 ` Jasen Betts <jasen@xnet.co.nz>

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