pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Diehl, Jeffrey <jdiehl@sandia.gov>
To: pgsql-sql@postgresql.org
Subject: Re: DB porting questions...
Date: Wed, 11 Apr 2001 16:29:48 -0700
Message-ID: <web-37075@davinci.ethosmedia.com> (raw)
In-Reply-To: <B51F0C636E578A4E832D3958690CD73E0130BEA7@es04snlnt>

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@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



view thread (11+ messages)  latest in thread

Message-ID: <web-37075@davinci.ethosmedia.com>
Permalink:  ../web-37075@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-37075@davinci.ethosmedia.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, jdiehl@sandia.gov
  Subject: Re: DB porting questions...
  In-Reply-To: <web-37075@davinci.ethosmedia.com>
  References: <B51F0C636E578A4E832D3958690CD73E0130BEA7@es04snlnt> <web-37075@davinci.ethosmedia.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox