gpt4 book ai didi

Postgresql:我们如何使用时间戳将时间和日期仅插入到变量中?

转载 作者:行者123 更新时间:2023-11-29 12:13:01 31 4
gpt4 key购买 nike

错误:插入时出现接近时间格式错误。

示例:

--Table "Test"  

create table test
(
name varchar(10),
date1 timestamp,
time1 timestamp
);

-- Insertion
insert into test values('xyz','03/03/2014','02:03:04');

最佳答案

“timestamp”类型包含时间和日期。您正在尝试分别插入日期和时间。使用日期和时间类型:

--Table "Test"

create table test
(
name varchar(10),
date1 date,
time1 time
);

-- Insertion
insert into test values('xyz','03/03/2014','02:03:04');

或者,只使用一个字段:

--Table "Test"

create table test
(
name varchar(10),
datetime timestamp

);

-- Insertion
insert into test values('xyz','03/03/2014 02:03:04');

我推荐第二种方法,因为可用的运算符和函数集要大得多,而且比较时间戳更容易。

关于Postgresql:我们如何使用时间戳将时间和日期仅插入到变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22140542/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com