【问题标题】:Convert column from Date type to Timestamp将列从日期类型转换为时间戳
【发布时间】:2015-09-01 14:10:20
【问题描述】:

我有一个表,其列名为modify,其类型为Date。我已将其转换为类型TIMESTAMP WITHOUT TIME ZONE

此列数据由触发器更新:

CREATE OR REPLACE FUNCTION trigA()
  RETURNS trigger AS
$BODY$
begin
    new.modify=current_date;
    return new;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE

它只是跟踪某人何时更新了行。

current_date 对于Date 来说还可以,但它没有时间,所以我想将其更改为:current_timestamp。但是根据manualcurrent_timestamp 给出timestamp with time zone

我浏览了整个页面,但找不到给出timestamp without time zone 类型的当前日期和时间的内容。

我的问题:如何将当前日期和时间插入timestamp without time zone 字段。

【问题讨论】:

  • 你的问题到底是什么?

标签: sql postgresql date datetime


【解决方案1】:

你应该使用LOCALTIMESTAMP

CREATE OR REPLACE FUNCTION trigA()
  RETURNS trigger AS
$BODY$
begin
    new.modify=LOCALTIMESTAMP;
    return new;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE

PostgreSQL manual 提及:

CURRENT_TIME 和 CURRENT_TIMESTAMP 传递带有时区的值; LOCALTIME 和 LOCALTIMESTAMP 提供没有时区的值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-26
    • 2016-10-05
    • 2013-09-27
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 1970-01-01
    相关资源
    最近更新 更多