Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f3BNTp884602 for ; Wed, 11 Apr 2001 19:29:52 -0400 (EDT) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.1) with HTTP id 37075; Wed, 11 Apr 2001 16:29:48 -0700 From: "Josh Berkus" Subject: Re: DB porting questions... To: "Diehl, Jeffrey" , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Wed, 11 Apr 2001 16:29:48 -0700 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200104/169 X-Sequence-Number: 2517 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