Subject Re: domain default value
Author Rick Roen
The default value is used ONLY when you do not specify the field in
the insert, update columns.

Rick

--- In firebird-support@yahoogroups.com, "kaczy27" <kaczy27@y...>
wrote:
>
> Hi,
>
> I have definde the domain as not null with default value. Like
this:
>
> CREATE DOMAIN MY_DOMAIN AS
> SMALLINT
> DEFAULT 0
> NOT NULL
>
> I have assumed that if I insert a new row providing null for the
> field using this domain, the default value would used.
>
> CREATE TABLE MY_TABLE (
> ID INTEGER,
> MY_FIELD MY_DOMAIN NOT NULL);
>
> So I was quite surprised when following command exceptioned:
>
> INSERT INTO MY_TABLE(ID, MY_FIELD) VALUES (10, NULL);
>
> and had to workaround this by similiar construct.
>
> if (field is null) then
> INSERT INTO MY_TABLE(ID) VALUES (:ID);
> else
> INSERT INTO MY_TABLE(ID, MY_FIELD) VALUES (:id, :my_field);
> end
>
>
> question? is it correct? does anyone else feel this counter-
> intuitive? is there a need for such explicit code?
>
> CUIN Kaczy
>