Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 3rd, 2006, 03:05 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 810 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 5 h 46 m 49 sec
Reputation Power: 19
Update Bug Or Me?

I just ran the following update SQL in Firebird 1.5 which should have swapped the values of two columns according to SQL set theory as I understand it. Instead, I ended up with the same value in each column.
UPDATE MYTABLE
SET FIELD1 = FIELD2,
FIELD2 = FIELD1;

Unlike a procedural language, this is suppose to work. Certainly according to my SQL Guru Joe Celko.
His book "SQL for Smarties" specifically states(page. 123):
==========
Each assignment in the <set clause list> is executed in parallel and each SET clause changes all the qualified rows at once.
....
This feature lets you write a statement that will swap the values in two columns thus:
UPDATE MyTable
SET a=b,b=a;
===========
Can anyone enlighten me?

Thanks,
Clive

Reply With Quote
  #2  
Old January 4th, 2006, 02:30 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,907 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 8 h 24 m 58 sec
Reputation Power: 279
Better call Joe for help, here is MySQL:
Code:
mysql> insert into pippo(field1, field2) values ('a', 'b');
Query OK, 1 row affected (0.19 sec)

mysql> select * from pippo;
+--------+--------+
| field1 | field2 |
+--------+--------+
| a      | b      |
+--------+--------+
1 row in set (0.05 sec)

mysql> update pippo set field1 = field2, field2 = field1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from pippo;
+--------+--------+
| field1 | field2 |
+--------+--------+
| b      | b      |
+--------+--------+
1 row in set (0.00 sec)

mysql> select version();
+---------------+
| version()     |
+---------------+
| 5.0.17-nt-max |
+---------------+
1 row in set (0.01 sec)

Reply With Quote
  #3  
Old January 4th, 2006, 02:34 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,907 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 8 h 24 m 58 sec
Reputation Power: 279
Ok, add another one for PostgreSQL (v 8.1) it works as expected, Joe would be happy!!
You can draw your conclusions on which database to choose

Reply With Quote
  #4  
Old January 4th, 2006, 01:34 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 810 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 5 h 46 m 49 sec
Reputation Power: 19
Oracle (of course ;> ) works as defined by Joe.
I find it much more troubling that different databases give different results for the same SQL than that some databases do not support features.
Now I am wondering what other areas of Firebird (and MySQL) provide unexpected results.
As the schemas I design are well normalized, my display and reporting SQL is often very complex.

Reply With Quote
  #5  
Old January 4th, 2006, 04:15 PM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,005 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 52 m 46 sec
Reputation Power: 67
Just want to add to the list

It works as expected in HSQLDB, Derby, FirstSQL, SQL Server and SQL Anywhere. It is not working with McKoi and Firebird 2.0 (Alpha) as well.

I posted a message to the Firebird mailing list, and will post the answer here.

Regards
Thomas
Comments on this post
pabloj agrees!

Reply With Quote
  #6  
Old January 5th, 2006, 04:01 AM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,005 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 52 m 46 sec
Reputation Power: 67
OK, here is the answer I got from the Firebird mailing list. Seems that this is known, and won't change in the future.

Ann is one of the major leads in the development of Firebird:
Quote:
A known and long standing bug - one that precedes the SQL standard.
Firebird treats the list of assignments in an update as if they
were a sequence of assignments in a code block. The SQL standard
treats them as if the target were one record and the source another.
We need to fix that, but haven't.

Our model is useful and defensible and a better standard (in my
opinion) would have established old and new contexts for updates
so both values could be referenced. However, we didn't have the
$20K plus a person needed to be on the committee, so we didn't
get a vote.

Regards,
Ann

Reply With Quote
  #7  
Old January 5th, 2006, 04:06 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 810 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 5 h 46 m 49 sec
Reputation Power: 19
Quote:
Originally Posted by shammat
OK, here is the answer I got from the Firebird mailing list. Seems that this is known, and won't change in the future.


This is, of course, troubling and IMO needs to be prominently documented.

Meanwhile, I am very grateful to you and Ann for documenting how Firebird does treat updates so that we can avoid unwelcome surprises in other UPDATE SQL.
Clive

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Update Bug Or Me?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT