Thread: set default: question

set default: question

From
Marco Bomben
Date:
Dear all,
            I've started using postgresql this week and I found it awesome!
I've a problem in understanding the "SET DEFAULT" command.

fssr2db=# ALTER TABLE fssr2calibs ALTER COLUMN  intvbn SET DEFAULT 139; ALTER TABLE

but:
fssr2db=# SELECT tag, intvbn from   fssr2calibs
WHERE tag = '100421-154052' OR tag = '100302-161107';
      tag      | intvbn
---------------+--------
 100302-161107 |    139
 100421-154052 |

and
fssr2db=# \d fssr2calibs
                Table "public.fssr2calibs"
     Column      |          Type           |   Modifiers
-----------------+-------------------------+---------------
 tag             | character varying(13)   |
 module          | integer                 |
 sidetype        | polarity                |
 chipnum         | numofchip               |
 pomonechipnum   | pomonechip              |
 fssr2daqchipnum | fssr2daqchip            |
 tchip           | real                    |
 tpcb            | real                    |
 vmodule         | real                    |
 imodule         | real                    |
 peltierstatus   | boolean                 |
 vpeltier        | real                    |
 ipeltier        | real                    |
 nchips          | real                    |
 sensorstatus    | bit(1)[]                |
 sensortype      | character varying(120)  |
 shortdettype    | shortdet                |
 vbias           | real                    |
 leakagecurr     | real                    |
 maskedchans     | integer[]               |
 noise           | real                    |
 thrdisp         | real[]                  |
 disvtn          | integer                 |
 vth             | integer[]               |
 vmin            | integer                 |
 vmax            | integer                 |
 vstep           | integer                 |
 comments        | character varying(1000) |
 fanon           | integer                 |
 n2flux          | real                    |
 troom           | real                    |
 intvbn          | integer                 | default 139
 shpvbp2         | integer                 |
 shpvbp1         | integer                 |
 blrvbp1         | integer                 |
 shaping         | integer                 |
 highgain        | boolean                 | default false
 blr             | boolean    


So I do see the effects of SET DEFAULT on the table as a whole (through \d <table name>)
but not on each row (I set the value for some of them and for some not before using SET DEFAULT).

Is there any way to get the default value for each single row?
I'm using postgres 8.4.3.

Many thanks in advance,
                                     regards,
                                                   Marco Bomben

--
"Human existence is based upon two pillars: Compassion and knowledge.
Compassion without knowledge is ineffective; knowledge without compassion is inhuman."
(Victor Frederick Weisskopf)
----------------------------------------------
http://marco.bomben.googlepages.com/

Re: set default: question

From
Tom Lane
Date:
Marco Bomben <marco.bomben@gmail.com> writes:
> I've a problem in understanding the "SET DEFAULT" command.
> fssr2db=# ALTER TABLE fssr2calibs ALTER COLUMN  intvbn SET DEFAULT 139;
> ...
> So I do see the effects of SET DEFAULT on the table as a whole (through \d
> <table name>)
> but not on each row (I set the value for some of them and for some not
> before using SET DEFAULT).

SET DEFAULT only establishes a default to use in future INSERT
operations; it doesn't affect any existing rows.  Perhaps you want
to do something like

    UPDATE fssr2calibs SET intvbn = 139 WHERE intvbn IS NULL

in addition to setting the default?

            regards, tom lane