PostgreSQL-to_时间戳未正确转换unix时间戳

PostgreSQL-to_时间戳未正确转换unix时间戳,postgresql,timestamp,Postgresql,Timestamp,我正在尝试获取当前UTC时间,并将其插入到PostgreSQL时间戳中。但它不能正常工作 我正在使用以下命令: INSERT INTO public.rt_block_height VALUES(to_timestamp('2018-09-09 00:36:00.778653', 'yyyy-mm-dd hh24:mi:ss.MS.US'), 83.7) 但是,当我检查结果时,它看起来是这样的: tutorial=# select * from rt_block_height;

我正在尝试获取当前UTC时间,并将其插入到PostgreSQL时间戳中。但它不能正常工作

我正在使用以下命令:

INSERT INTO public.rt_block_height 
VALUES(to_timestamp('2018-09-09 00:36:00.778653', 'yyyy-mm-dd hh24:mi:ss.MS.US'), 83.7)
但是,当我检查结果时,它看起来是这样的:

tutorial=# select * from rt_block_height;
          time           | block_height
-------------------------+--------------
 2018-09-09 00:48:58.653 |         83.7
(1 row)
我不知道是什么导致了这种不匹配

FYI,这里是我的表源代码:

CREATE TABLE IF NOT EXISTS public.rt_BLOCK_HEIGHT
(
"time" timestamp without time zone,
BLOCK_HEIGHT double precision
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public.rt_BLOCK_HEIGHT
OWNER to postgres;
SELECT create_hypertable('rt_BLOCK_HEIGHT', 'time');

格式字符串中存在逻辑错误,因为您不应同时使用
MS
US
。但是,您根本不需要该函数,只需将字符串转换为
timestamp

INSERT INTO public.rt_block_height 
VALUES('2018-09-09 00:36:00.778653'::timestamp, 83.7)

to_timestamp
to_date
用于处理无法通过简单转换转换的输入格式。对于大多数标准的日期/时间格式,只需将源字符串转换为所需的数据类型就可以了,而且要容易得多