Thread: default timestamp and default autoinc

default timestamp and default autoinc

From
"Jarmo Paavilainen"
Date:
Hi,

Does pg have "default timestamp" and "default autoinc" as default values
(used in CREATE TABLE).

And where is the PostgreSQL reference guide. Or actually/maybe how do I make
html files of the sgml files that are included with the CVS tree (what do I
need, jade? and where do I get it?)?

// Jarmo


Re: default timestamp and default autoinc

From
"Edward Q. Bridges"
Date:
On Mon, 6 Nov 2000 15:00:19 +0100, Jarmo Paavilainen wrote:

> Hi,
>
> Does pg have "default timestamp" and "default autoinc" as default values
> (used in CREATE TABLE).
>

here's an example that shows how to default a timestamp and how to use a
sequence to auto-increment a primary key column:

CREATE SEQUENCE personid_seq;
CREATE TABLE person (
    person_id       INT4 NOT NULL DEFAULT nextval('personid_seq'),
    create_date     TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    modify_date     TIMESTAMP NOT NULL,
    firstname       VARCHAR (128) NOT NULL,
    lastname        VARCHAR (128),
PRIMARY KEY (person_id));
CREATE UNIQUE INDEX personid_key
    ON person(person_id);
CREATE TRIGGER trg_modtime BEFORE INSERT OR UPDATE
    ON person FOR EACH ROW
    EXECUTE PROCEDURE setmodtime();

the trigger updates the modify_date column, and you could use that
as an alternate way of adding a timestamp.


> And where is the PostgreSQL reference guide. Or actually/maybe how do I make
> html files of the sgml files that are included with the CVS tree (what do I
> need, jade? and where do I get it?)?
>

bash# cd $POSTGRES_SOURCE_TREE/doc
bash# gmake install

should create man pages and html files for all docs


HTH
ed