Re: example of insert timestamp

Поиск
Список
Период
Сортировка
От Gregory Williamson
Тема Re: example of insert timestamp
Дата
Msg-id 8B319E5A30FF4A48BE7EEAAF609DB233015E33E0@COMAIL01.digitalglobe.com
обсуждение исходный текст
Ответ на example of insert timestamp  (David Bear <david.bear@asu.edu>)
Ответы Re: example of insert timestamp  (Jamie A Lawrence <postgres@jal.org>)
Список pgsql-admin

David --

>
> I want to have a table with a timestamp field that automatically gets the
> value of now() on insert. The timestamp will never be updated. I assume I
> need to create a trigger to do this. If there is an easier way, please
> advise.

Perhaps, make the column so it has a default value of now, land then insert without specifying the timestamp column so it gets the default value:

create table foo (q_i_time timestamp with time zone not null default now(), someval int);

CREATE TABLE
billing=# insert into foo (someval) values (22);
INSERT 0 1
billing=# insert into foo (someval) values (26);
INSERT 0 1
billing=# insert into foo (someval) values (1);
INSERT 0 1
billing=# select * from foo;
           q_i_time            | someval
-------------------------------+---------
 2008-02-25 17:23:03.247619-08 |      22
 2008-02-25 17:23:07.43922-08  |      26
 2008-02-25 17:23:10.111189-08 |       1
(3 rows)

HTH,

Greg Williamson
Senior DBA
GlobeXplorer LLC, a DigitalGlobe company

Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information and must be protected in accordance with those provisions. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

(My corporate masters made me say this.)

В списке pgsql-admin по дате отправления:

Предыдущее
От: David Bear
Дата:
Сообщение: Re: example of insert timestamp
Следующее
От: Jamie A Lawrence
Дата:
Сообщение: Re: example of insert timestamp