dbTalk Databases Forums  

Order of evaluation in update clause?

comp.databases.sybase comp.databases.sybase


Discuss Order of evaluation in update clause? in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gregory Bond
 
Posts: n/a

Default Order of evaluation in update clause? - 08-23-2004 , 08:20 PM






Consider this:

select 1 as oldid, 2 as id into #tmp;
update #tmp set id=oldid, oldid=0;

Is it guaranteed that id will be non-zero? I.e. is it guaranteed that
the order of assignments in an update matches the order they are
written in?



Reply With Quote
  #2  
Old   
David Kerber
 
Posts: n/a

Default Re: Order of evaluation in update clause? - 08-24-2004 , 07:06 AM






In article <wwpt5h5o30.fsf (AT) hellcat (DOT) itga.com.au>, gnb (AT) itga (DOT) com.au says...
Quote:
Consider this:

select 1 as oldid, 2 as id into #tmp;
update #tmp set id=oldid, oldid=0;

Is it guaranteed that id will be non-zero? I.e. is it guaranteed that
the order of assignments in an update matches the order they are
written in?
Probably depends on your database version, but in ASA 7, the assignment
order is NOT guaranteed.

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).


Reply With Quote
  #3  
Old   
Bret Halford
 
Posts: n/a

Default Re: Order of evaluation in update clause? - 08-24-2004 , 11:47 AM



Gregory Bond <gnb (AT) itga (DOT) com.au> wrote

Quote:
Consider this:

select 1 as oldid, 2 as id into #tmp;
update #tmp set id=oldid, oldid=0;

Is it guaranteed that id will be non-zero? I.e. is it guaranteed that
the order of assignments in an update matches the order they are
written in?

The order of assignments doesn't matter when it comes to
column values. The values on the RHS are taken from the
original state of the table.

If you did this:

select 1 as oldid, 2 as id into #tmp;
update #tmp set id = oldid, oldid = id
select * from #tmp

you should get id = 1 oldid = 2

The rules are different when variables are involved.
It is best not to rely on placement in that case - instead
write two update statements in the order you want the
updates to occur.

-bret


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.