Re: DB porting questions...
От | Josh Berkus |
---|---|
Тема | Re: DB porting questions... |
Дата | |
Msg-id | web-37075@davinci.ethosmedia.com обсуждение исходный текст |
Ответ на | DB porting questions... ("Diehl, Jeffrey" <jdiehl@sandia.gov>) |
Список | 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 informationtechnology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco
В списке pgsql-sql по дате отправления: