简体   繁体   English

如何在 postgresql 中添加时间为 09.00 点的默认时间戳?

[英]How to add a default timestamp with time 09.00 o'clock in postgresql?

I am trying to add a default timetable into my query with a chosen time, 09.00 o'clock.我正在尝试将默认时间表添加到我的查询中,并选择时间 09:00。 The type of the column was 'date', I changed it to 'timestamp', my assignment sais so.列的类型是“日期”,我将其更改为“时间戳”,我的作业是这样说的。 I don't know what to do now.我现在不知道该怎么办。 I am very new to this and trying to understand queries with 'timestamp'.我对此很陌生,并试图理解带有“时间戳”的查询。

This is what I have so far:这是我到目前为止:

ALTER TABLE note
    ALTER COLUMN entered TYPE timestamp SET DEFAULT;

I don't know what to do next.我不知道接下来要做什么。 Any help is appricieted!任何帮助是appricieted!

The ALTER COLUMN allows to provide an expression for the cast through the USING keyword. ALTER COLUMN 允许通过USING关键字为强制转换提供表达式。 As you already have a date, you can convert it to a timestamp by adding a time:由于您已经有了日期,您可以通过添加时间将其转换为时间戳:

ALTER TABLE note
    ALTER COLUMN entered TYPE timestamp using entered + time '09:00';

If you also want to set a default value to "today at 09:00" you can do that in the same statement:如果您还想将默认值设置为“今天 09:00”,您可以在同一语句中执行此操作:

ALTER TABLE note
    ALTER COLUMN entered TYPE TIMESTAMP USING entered + time '09:00', 
    ALTER COLUMN entered SET DEFAULT current_date + time '09:00';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM