Subject | RE: [firebird-support] Re: Update numeric problem |
---|---|
Author | Dunbar, Norman (Capgemini) |
Post date | 2010-08-24T08:14:13Z |
Morning Tim,
trigger can prevent updates to the total column.
However, there is an even simpler reason why the updates are not
happening:
SQL> create table funny(id integer, my_value decimal(10,2));
SQL> commit;
SQL> insert into funny (id, my_value) values (10, null);
SQL> insert into funny (id, my_value) values (20, 20.2);
SQL> commit;
SQL> select * from funny;
ID MY_VALUE
============ =====================
10 <null>
20 20.20
SQL> update funny set my_value=my_value + 10;
SQL> commit;
SQL> select * from funny;
ID MY_VALUE
============ =====================
10 <null>
20 30.20
SQL> commit;
If you have a null "value" in a column, you cannot add, subtract etc
that null value. So, changes to "some" values don't seem to work.
The solution in this case is to update the table converting NULL into
0.0 and then adding a NOT NULL constraint to the column in question.
Unfortunatley, this will have to be done by creating a new column with
NOT NULL, copying the existing values over to it, dropping the old
column and renaming the new one.
Unless, of course, it's possibly (now) to do an ALTER table ... alter
column ... not null - which I've been unable to find by experiment or in
the release notes etc!
Cheers,
Norman.
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.
We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.
If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk
>> The only trouble is that:Not necessarily. It is possible that, under certain circumstances, the
>> update mytable set total=total+10.12,
>> databasename='Firebird' where mykey=10
>>
>> updates all fields except total. And the whole thing works
>> most of the time. I think this would suggest the triggers are fine.
trigger can prevent updates to the total column.
However, there is an even simpler reason why the updates are not
happening:
SQL> create table funny(id integer, my_value decimal(10,2));
SQL> commit;
SQL> insert into funny (id, my_value) values (10, null);
SQL> insert into funny (id, my_value) values (20, 20.2);
SQL> commit;
SQL> select * from funny;
ID MY_VALUE
============ =====================
10 <null>
20 20.20
SQL> update funny set my_value=my_value + 10;
SQL> commit;
SQL> select * from funny;
ID MY_VALUE
============ =====================
10 <null>
20 30.20
SQL> commit;
If you have a null "value" in a column, you cannot add, subtract etc
that null value. So, changes to "some" values don't seem to work.
The solution in this case is to update the table converting NULL into
0.0 and then adding a NOT NULL constraint to the column in question.
Unfortunatley, this will have to be done by creating a new column with
NOT NULL, copying the existing values over to it, dropping the old
column and renaming the new one.
Unless, of course, it's possibly (now) to do an ALTER table ... alter
column ... not null - which I've been unable to find by experiment or in
the release notes etc!
Cheers,
Norman.
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.
We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.
If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk