Thread: Default value for bit datatype

Default value for bit datatype

From
Terry Fielder
Date:
When I try to do a default value for the bit datatype, eg:
CREATE TABLE my_calendar (
 ID serial NOT NULL ,
 Global_field bit DEFAULT 0 NOT NULL ,
)

I get the message:
ERROR:  Attribute 'global_field' is of type 'bit' but default expression
is of type 'int4'
        You will need to rewrite or cast the expression

I have tried (bit) 0, bit(0), bit 0, etc but have not found a way to do
casting.  Can anyone help me to set a default value for a bit datatype
field?

Thanks

Terry Fielder
terry@greatgulfhomes.com


Re: Default value for bit datatype

From
missive@frontiernet.net (Lee Harr)
Date:
On Wed, 06 Jun 2001 09:57:02 -0400, Terry Fielder <terry@greatgulfhomes.com>:

CREATE TABLE my_calendar (
 ID serial NOT NULL ,
 Global_field bit DEFAULT 0::bit NOT NULL
);


Re: Default value for bit datatype

From
Doug McNaught
Date:
Terry Fielder <terry@greatgulfhomes.com> writes:

> When I try to do a default value for the bit datatype, eg:
> CREATE TABLE my_calendar (
>  ID serial NOT NULL ,
>  Global_field bit DEFAULT 0 NOT NULL ,
> )
>
> I get the message:
> ERROR:  Attribute 'global_field' is of type 'bit' but default expression
> is of type 'int4'
>         You will need to rewrite or cast the expression
>
> I have tried (bit) 0, bit(0), bit 0, etc but have not found a way to do
> casting.  Can anyone help me to set a default value for a bit datatype
> field?

Try:

  Global_field bit DEFAULT '0'::bit NOT NULL

Yes, it's a little weird.  ;)

-Doug
--
The rain man gave me two cures; he said jump right in,
The first was Texas medicine--the second was just railroad gin,
And like a fool I mixed them, and it strangled up my mind,
Now people just get uglier, and I got no sense of time...          --Dylan