Subject | Re: Exchange two column values in a single statement... |
---|---|

Author | Adam |

Post date | 2006-10-02T23:20:49Z |

> ...without a temporary field ;)Milan,

>

> update t1 set a = a+b, b = a-b, a = a-b;

I think you are relying on two non standard behaviours.

1. Including the same field twice in a single update statement.

2. I am pretty sure SQL says that the original values should remain

constant during the operation, and Firebird does not do this.

Assume before the update, a = 1 and b =2:

Firebird evaluates:

a = a + b ==> 3

b = a - b ==> 3 - 2 ==> 1

a = a - b ==> 3 - 1 ==> 2

Where SQL says it should be

a = a + b ==> 3

b = a - b ==> 1 - 2 = -1 (the new value of a is not used)

The second assignment to a is not valid.

Still, very clever.

Adam