Re: Table with default value

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Sharon Cowling <sharon(dot)cowling(at)sslnz(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Table with default value
Date: 2002-01-11 11:15:04
Message-ID: 1010747706.781.2.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, 2002-01-11 at 03:14, Sharon Cowling wrote:
>
> user=> \d
> Table "person4"
> Attribute | Type | Modifier
> ------------------+-----------------------+--------------
...
> drivers_licence | character varying(20) | default 'No'
...
>
> user=> select * from person4;
> person_id | firstname | lastname | dob | street | suburb | city | homephone | workphone | mobile | type | date_approved | approved_by | vehicle_type | vehicle_rego | drivers_licence | firearms_licence | notes
> -----------+-----------+----------+------------+--------+--------+------+-----------+-----------+--------+----------------+---------------+-------------+--------------+--------------+-----------------+------------------+-------
> 778 | sdf | sdf | 11/11/1977 | sf | | dsf | | | | Owner/Relative | 11/01/2002 | test | | | | |
> (1 row)
>
> As you can see there is no default value of 'No' for drivers licence.

The default only operates if you do an insert without mentioning the
column. It will not override an explicitly inserted null or empty
string.

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"Enter into his gates with thanksgiving, and into his
courts with praise. Be thankful unto him, and bless
his name." Psalms 100:4

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Al Dev 2002-01-13 18:08:57 Commercial: New Book!! PostgreSQL book is released into the market
Previous Message Tom Lane 2002-01-11 05:11:23 Re: How do you do a subselect in postgresql?