Skip site navigation (1) Skip section navigation (2)

Column default

From: "Keith Worthington" <keithw(at)narrowpathinc(dot)com>
To: "PostgreSQL Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Column default
Date: 2005-02-14 19:50:42
Message-ID: 20050214194037.M95860@narrowpathinc.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi All,

I am having difficulty understanding the use of defaults.

I have a table with defaults defined in three columns.  When I run a function
that inserts/or updates records the default value is not written into the
record.  I thought this was a result of updates occurring and not inserts. 
So, I changed the source table to have the same defaults.  However when I use
the COPY command to place data in the source table the defaults do not appear
to be applied there either.

When I run a query on the table specifying WHERE ptos_uom_factor ISNULL I get
lots of records back.  I though that using a default would prevent this outcome.

When is the default value applied?  On INSERT? UPDATE? COPY? None of the above?

TIA

        Column        |          Type          |            Modifiers           
 
----------------------+------------------------+--------------------------------
-
 id                   | character varying(20)  | not null
 description          | character varying(30)  | not null
 item_class           | smallint               | not null
 inactive             | boolean                | not null
 sales_description    | character varying(160) | 
 purchase_description | character varying(160) | 
 last_unit_cost       | real                   | not null
 costing_method       | smallint               | not null
 sales_gl_account     | character varying(15)  | 
 inventory_gl_account | character varying(15)  | 
 cogs_gl_account      | character varying(15)  | 
 item_type            | character varying(8)   | 
 unit_of_measure      | character varying(6)   | default 'ea'::character varying
 weight               | real                   | 
 reorder_point        | real                   | 
 reorder_quantity     | real                   | 
 purchase_uom         | character varying(6)   | default 'ea'::character varying
 ptos_uom_factor      | real                   | default 1


Kind Regards,
Keith

Responses

pgsql-novice by date

Next:From: Jeff EckermannDate: 2005-02-14 20:04:20
Subject: Re: Column default
Previous:From: DeepbluesDate: 2005-02-14 19:11:19
Subject: Question on PL/Perl

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group