Re: DB porting questions...

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: "Diehl, Jeffrey" <jdiehl(at)sandia(dot)gov>, pgsql-sql(at)postgresql(dot)org
Subject: Re: DB porting questions...
Date: 2001-04-11 23:29:48
Message-ID: web-37075@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mike,

You'll be overjoyed to know that both of your questions have simple
answers.

> 1)
> I have a table:
> create table a (
> t timestamp not null,
> ...
> );
>
> I'm thinking that I can define a.t as not null default=now(). But
> will this
> work? That is, will it update a.t when I modified a given record?

No. Defaults only take effect when you INSERT a record, and only if you
don't supply a value. Thus, a.t will be updated with the time each new
record was added. If you want the time a record was modified, you need
to add an update trigger to the table that auto-updates the t field
whenever other changes are made.

See the development documentation for information on writing triggers.

>
>
> 2)
> I have another table:
> create table b (
> id int not null AUTO_INCREMENT,
> ...
> );
>
> To reproduce this behavior, I believe I need to use a sequence. The
> problem
> is that I have a lot of data to import into this table. How do I
> import the
> old data without colliding with the new sequence numbers?

Not a problem at all. Sequence numbers are merely defaults, and may be
overridden by a specific insert. Thus:

1. Create the id field as type SERIAL.
2. Insert your records into the new table, including the ID value.
3. Crank up the SERIAL sequence to the number of the highest ID present:

SELECT SETVAL('b_id_seq',10315);

-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joel Burton 2001-04-11 23:34:11 Re: DB porting questions...
Previous Message Michael Ansley 2001-04-11 23:29:11 RE: DB porting questions...