New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting default value of field, when updating field with NULL value [CORE1311] #1730
Comments
Commented by: @pcisar AFAIK this is correct according to SQL standard. Default value is assigned only when no value is provided at all (explicit NULL is a value). |
Commented by: Dejan Schild (schild) It's ok. Maybe to add some directive to INSERT/UPDATE command, like this: CREATE VIEW VE_KALKROBE( CREATE trigger ve_kalkrobe_bi5 for ve_kalkrobe CREATE trigger ve_kalkrobe_bu5 for ve_kalkrobe Naturally, use this only for NOT NULL fields who has default value. |
Modified by: @pcisarWorkflow: jira [ 12285 ] => Firebird [ 14787 ] |
Commented by: Cosmin Apreutesei (cosmin_ap2) This bit me too, default value are pretty useless in conjunction with updatable views. What's a standard good for if it cannot make its own specified features work together? AFAIK MSSQL has the keyword default which is a better workaround to the problem, ie. you can say: insert into t (c1, c2) values (coalesce(new.c1, default), new.c2) |
Modified by: @dyemanovassignee: Dmitry Yemanov [ dimitr ] |
Commented by: @asfernandes Dmitry, are you going to implement UPDATE ... SET field = DEFAULT or INSERT ... VALUES (x, y, DEFAULT)? If yes, this seems as same blr verb needed to support ALTER ... ADD ... NOT NULL. |
Commented by: @dyemanov I had such intention, but not in the nearest future. Feel free to jump in and intercept this task if you wish ;-) |
Modified by: @asfernandes |
Commented by: @mrotteveel The current request is not in line with the SQL standard, the SQL standard way would be to use the context value DEFAULT, which will use the column default (or NULL if there is no column default). |
Modified by: @mrotteveel |
Modified by: @asfernandesstatus: Open [ 1 ] => Resolved [ 5 ] resolution: Won't Fix [ 2 ] assignee: Dmitry Yemanov [ dimitr ] => |
Modified by: @pcisarstatus: Resolved [ 5 ] => Closed [ 6 ] |
Modified by: @pavel-zotovstatus: Closed [ 6 ] => Closed [ 6 ] QA Status: Covered by another test(s) Test Details: See test for CORE5449 |
Submitted by: Dejan Schild (schild)
Block progress on CORE3073
Is replaced by CORE5449
Votes: 2
A mandatory field that has been assigned a default value, when updating it with NULL, it's set to NULL, instead of acquiring a preset default value.
For example:
CREATE TABLE KALKULACIJA (
KALK_UID BIGINT NOT NULL,
K_CARINA DOUBLE PRECISION DEFAULT 0 NOT NULL
);
The following command:
INSERT INTO KALKULACIJA (KALK_UID, K_CARINA)
VALUES (1, NULL);
will raise an error:
The insert failed because a column definition includes validation constraints.
validation error for column K_CARINA, value "*** null ***".
It should write following values into the table: KALK_UID=1 and K_CARINA=0 (it's default value).
Reason: When using updatable view, then we must update all fields in table, not just fields that are to be updated. In this situation default values for fields are unusable, and we have to write triggers that will check if fields are NULL. That is double work.
====== Test Details ======
See test for CORE5449
The text was updated successfully, but these errors were encountered: