最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PostgreSQL數(shù)據(jù)庫timestamp數(shù)據(jù)類型精度進(jìn)位問題解析

 更新時間:2024年11月04日 16:45:23   作者:靖節(jié)先生  
PostgreSQL是一款功能強(qiáng)大的開源關(guān)系型數(shù)據(jù)庫管理系統(tǒng),起源于1986年的POSTGRES項目,它支持多種數(shù)據(jù)類型,包括數(shù)值類型、字符串類型、日期時間類型等,本文介紹PostgreSQL數(shù)據(jù)庫timestamp數(shù)據(jù)類型精度進(jìn)位問題,感興趣的朋友一起看看吧

PostgreSQL數(shù)據(jù)庫timestamp數(shù)據(jù)類型精度進(jìn)位問題

1. PostgreSQL簡介

PostgreSQL 起源于 1986 年加州大學(xué)伯克利分校開發(fā)的 POSTGRES 項目。它經(jīng)過多年的發(fā)展和演進(jìn),成為了一個功能強(qiáng)大、開源的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)。

PostgreSQL 本身是開源的,通常不存在嚴(yán)格意義上的商業(yè)版和社區(qū)版之分。
官網(wǎng)地址:https://www.postgresql.org/
在官網(wǎng)上,您可以獲取更詳細(xì)和準(zhǔn)確的信息,包括最新的特性、下載安裝指南、文檔教程等。

2. PostgreSQL特點

1.強(qiáng)大的功能:支持豐富的特性,如復(fù)雜查詢、事務(wù)處理、存儲過程、視圖等。
2.開源和社區(qū)驅(qū)動:擁有活躍的開源社區(qū),不斷進(jìn)行改進(jìn)和更新。
3.可擴(kuò)展性:易于擴(kuò)展功能和數(shù)據(jù)類型。
4.標(biāo)準(zhǔn)符合性:高度符合 SQL 標(biāo)準(zhǔn)。
5.安全性:提供多種安全機(jī)制,包括用戶認(rèn)證、權(quán)限管理等。

3. PostgreSQL優(yōu)缺點

優(yōu)點:
1.穩(wěn)定性高:經(jīng)過長期的實踐和優(yōu)化,具有出色的穩(wěn)定性和可靠性。
2.數(shù)據(jù)完整性:確保數(shù)據(jù)的一致性和完整性。
3.跨平臺支持:可在多種操作系統(tǒng)上運(yùn)行。
4.豐富的文檔和支持:有詳細(xì)的官方文檔和活躍的社區(qū)支持。

缺點:
1.配置相對復(fù)雜:對于新手來說,初始配置可能具有一定的難度。
2.資源消耗:在處理大型數(shù)據(jù)集時,可能需要較多的系統(tǒng)資源。

4. PostgreSQL數(shù)據(jù)類型

包括數(shù)值類型(如整數(shù)、浮點數(shù))、字符串類型(固定長度和可變長度)、日期和時間類型、布爾類型、數(shù)組類型、枚舉類型、幾何類型等。

數(shù)據(jù)類型說明精度特點案例
smallint小范圍整數(shù)2 字節(jié)占用存儲空間小,適用于數(shù)據(jù)范圍較小的整數(shù)smallint: 100
integer(或 int常規(guī)整數(shù)4 字節(jié)常見的整數(shù)類型,能滿足大多數(shù)常規(guī)整數(shù)需求integer: 2000
bigint大范圍整數(shù)8 字節(jié)用于存儲非常大的整數(shù)數(shù)值bigint: 9000000000
decimal(或 numeric用戶指定精度和小數(shù)位數(shù)的精確數(shù)值取決于指定的精度和小數(shù)位數(shù)精度和小數(shù)位數(shù)可自定義,適用于對精度要求高的數(shù)值計算decimal(5, 2): 123.45
real單精度浮點數(shù)4 字節(jié)大約 6 位十進(jìn)制精度存儲精度要求不高的浮點數(shù)
double precision雙精度浮點數(shù)8 字節(jié)大約 15 位十進(jìn)制精度適用于高精度的浮點數(shù)計算
char(n)固定長度的字符字符串,不足長度用空格填充n 個字符長度固定,存儲和讀取效率較高char(10): 'hello '
varchar(n)可變長度的字符字符串,最大長度為 n最大 n 個字符節(jié)省存儲空間,適用于長度不固定的字符串varchar(20): 'hello world'
text可變長度的字符字符串,無長度限制無限制可存儲大量文本數(shù)據(jù)text: 'This is a long text.'
date日期格式為 YYYY-MM-DD只存儲日期信息date: '2024-08-08'
time時間,不包含日期格式為 HH:MM:SS只存儲時間信息time: '12:30:00'
timestamp日期和時間格式為 YYYY-MM-DD HH:MM:SS ,支持到微秒級別(6 位小數(shù))同時包含日期和時間信息timestamp: '2024-08-08 12:30:00.123456'
boolean布爾值真或假用于表示邏輯值boolean: true
array數(shù)組取決于元素類型和數(shù)組長度可以存儲相同數(shù)據(jù)類型的元素集合integer[]: '{1, 2, 3}'
jsonJSON 數(shù)據(jù)無固定精度方便存儲和處理 JSON 格式的數(shù)據(jù)json: '{"key": "value"}'
uuid通用唯一標(biāo)識符128 位用于生成唯一標(biāo)識符uuid: 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'

5. PostgreSQL注意事項

PostgreSQL數(shù)據(jù)庫timestamp數(shù)據(jù)類型精度存在進(jìn)位問題,先說結(jié)論,在測試驗證。

PostgreSQL只能存儲最多6位的小數(shù)部分。因此,當(dāng)嘗試存儲超過6位的分?jǐn)?shù)秒時,會發(fā)生以下情況之一:
如果額外的數(shù)字導(dǎo)致整個分?jǐn)?shù)秒部分超過 999999 微秒,則整個時間值會進(jìn)位到下一秒,剩余的部分會被截斷或者四舍五入到 6 位小數(shù)。
在這種情況下,2024-08-07 16:19:23.999999999 會被處理為 2024-08-07 16:19:24.000000。
如果你使用的是某種客戶端或者編程語言接口來處理這個時間值,在插入之前它可能會自動進(jìn)行四舍五入或截斷。

比如,
截取前三位數(shù)據(jù):小于 2024-08-07 16:19:23.999999500
進(jìn)位數(shù)據(jù):[2024-08-07 16:19:23.999999500 - 2024-08-07 16:19:23.999999999]

通過指定精度數(shù)據(jù)庫中仍然會保存6位,但是指定精度3時后三位始終為0,精度6則保存6位。

SELECT * FROM crm.t_wx_user_1 WHERE 1=1;
SELECT user_id, to_char(last_login_time, 'YYYY-MM-DD HH24:MI:SS.US'), to_char(create_time, 'YYYY-MM-DD HH24:MI:SS.US') FROM crm.t_wx_user_1 WHERE 1=1;
-- last_login_time timestamp,-- 》timestamp(3)
ALTER TABLE crm.t_wx_user_1 ALTER COLUMN last_login_time TYPE TIMESTAMP(3) WITHOUT TIME ZONE;
ALTER TABLE crm.t_wx_user_1 ALTER COLUMN create_time TYPE TIMESTAMP(6) WITHOUT TIME ZONE;

注意問題:
PostgreSQL 的 timestamp 類型默認(rèn)只支持到微秒級別(6位小數(shù)),為什么select出來的數(shù)據(jù)中展示三位2024-08-07 16:19:23.999?
PostgreSQL 的 timestamp 類型確實支持到微秒級別(6位小數(shù))。然而,默認(rèn)情況下,當(dāng)您從數(shù)據(jù)庫中查詢 timestamp 值時,PostgreSQL 會將結(jié)果顯示為毫秒級別(3位小數(shù))以提高可讀性。這是默認(rèn)的行為,但是您可以更改輸出的精度。案例如下。

--PostgreSQL數(shù)據(jù)庫timestamp數(shù)據(jù)類型精度進(jìn)位問題
--# 1.PostgreSQL數(shù)據(jù)庫數(shù)據(jù)類型
-- 數(shù)據(jù)庫版本,PostgreSQL 15.3 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
SELECT version();
-- 創(chuàng)建數(shù)據(jù)庫
-- crm.t_wx_user_1 definition
-- Drop table
-- DROP TABLE crm.t_wx_user_1;
CREATE TABLE crm.t_wx_user_1 (
	user_id int8 NOT NULL,
	union_id varchar(50) NULL,
	open_id varchar(50) NULL,
	last_login_time timestamp NULL,
	privacy_agreement_version int8 NOT NULL DEFAULT 0,
	create_time timestamp NOT NULL,
	update_time timestamp NOT NULL DEFAULT '1970-01-01 00:00:00'::timestamp without time zone,
	delete_flag int2 NOT NULL DEFAULT 0,
	delete_time timestamp NOT NULL DEFAULT '1970-01-01 00:00:00'::timestamp without time zone,
	first_login_time timestamp NULL,
	created_by int8 NOT NULL DEFAULT '-1'::integer,
	updated_by int8 NOT NULL DEFAULT '-1'::integer,
	inst_id int8 NULL,
	CONSTRAINT t_wx_user_pkey_1 PRIMARY KEY (user_id)
);
CREATE INDEX idx_t_wx_user_open_id_1 ON crm.t_wx_user_1 USING btree (open_id);
CREATE INDEX idx_t_wx_user_union_id_1 ON crm.t_wx_user_1 USING btree (union_id);
CREATE UNIQUE INDEX uniq_wx_userid_unionid_openid_1 ON crm.t_wx_user_1 USING btree (user_id, union_id, open_id);
-- 測試驗證數(shù)據(jù)庫
select * from crm.t_wx_user_1 order by user_id  ;
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,支持類型 2024-08-07 16:19:23.142,正常插入數(shù)據(jù)庫
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230000, '1', '1', '2024-08-07 16:19:23.142', 0, '2024-07-12 16:52:39.674', '2024-08-07 16:19:23.142', 0, '1970-01-01 00:00:00.000', '2024-07-12 16:52:39.674', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,6位數(shù)據(jù)類型 2024-08-07 16:19:23.123456,截斷前三位插入數(shù)據(jù)庫
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230001, '1', '1', '2024-08-07 16:19:23.123456', 0, '2024-07-12 16:52:39.123456', '2024-08-07 16:19:23.123456', 0, '1970-01-01 00:00:00.123456', '2024-07-12 16:52:39.123456', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,3個9驗證 2024-08-07 16:19:23.999,正常插入數(shù)據(jù)庫
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230002, '1', '1', '2024-08-07 16:19:23.999', 0, '2024-07-12 16:52:39.999', '2024-08-07 16:19:23.999', 0, '1970-01-01 00:00:00.999', '2024-07-12 16:52:39.999', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,4個9驗證 2024-08-07 16:19:23.9999,截斷前三位插入數(shù)據(jù)庫
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230003, '1', '1', '2024-08-07 16:19:23.9999', 0, '2024-07-12 16:52:39.9999', '2024-08-07 16:19:23.9999', 0, '1970-01-01 00:00:00.9999', '2024-07-12 16:52:39.9999', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,6個9驗證 2024-08-07 16:19:23.999999,截斷前三位插入數(shù)據(jù)庫
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230004, '1', '1', '2024-08-07 16:19:23.999999', 0, '2024-07-12 16:52:39.999999', '2024-08-07 16:19:23.999999', 0, '1970-01-01 00:00:00.999999', '2024-07-12 16:52:39.999999', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999999,會進(jìn)位,存到數(shù)據(jù)庫為:2024-08-07 16:19:24.000
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230005, '1', '1', '2024-08-07 16:19:23.999999999', 0, '2024-07-12 16:52:39.999999999', '2024-08-07 16:19:23.999999999', 0, '1970-01-01 00:00:00.999999999', '2024-07-12 16:52:39.999999999', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,查詢操作,9個9驗證 2024-08-07 16:19:23.999999999,會進(jìn)位,把2024-08-07 16:19:24.000的也查詢出來。
select * from crm.t_wx_user_1 where last_login_time <= '2024-08-07 16:19:23.999999999';
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個值驗證 2024-08-07 16:19:23.123456789,截斷前三位插入數(shù)據(jù)庫
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230006, '1', '1', '2024-08-07 16:19:23.123456789', 0, '2024-07-12 16:52:39.123456789', '2024-08-07 16:19:23.123456789', 0, '1970-01-01 00:00:00.123456789', '2024-07-12 16:52:39.123456789', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,查詢操作,9個9驗證 2024-08-07 16:19:23.999999999,會進(jìn)位,把2024-08-07 16:19:24.000的也查詢出來。
select * from crm.t_wx_user_1 where last_login_time <= '2024-08-07 16:19:23.999999999';
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999998,會進(jìn)位,存到數(shù)據(jù)庫為:2024-08-07 16:19:24.000
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230007, '1', '1', '2024-08-07 16:19:23.999999998', 0, '2024-07-12 16:52:39.999999998', '2024-08-07 16:19:23.999999998', 0, '1970-01-01 00:00:00.999999998', '2024-07-12 16:52:39.999999998', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999001,截斷前三位插入數(shù)據(jù)庫
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230008, '1', '1', '2024-08-07 16:19:23.999999001', 0, '2024-07-12 16:52:39.999999001', '2024-08-07 16:19:23.999999001', 0, '1970-01-01 00:00:00.999999001', '2024-07-12 16:52:39.999999001', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999991,進(jìn)位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230009, '1', '1', '2024-08-07 16:19:23.999999991', 0, '2024-07-12 16:52:39.999999991', '2024-08-07 16:19:23.999999991', 0, '1970-01-01 00:00:00.999999991', '2024-07-12 16:52:39.999999991', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999990,進(jìn)位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230010, '1', '1', '2024-08-07 16:19:23.999999990', 0, '2024-07-12 16:52:39.999999990', '2024-08-07 16:19:23.999999990', 0, '1970-01-01 00:00:00.999999990', '2024-07-12 16:52:39.999999990', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999900,進(jìn)位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230011, '1', '1', '2024-08-07 16:19:23.999999900', 0, '2024-07-12 16:52:39.999999900', '2024-08-07 16:19:23.999999900', 0, '1970-01-01 00:00:00.999999900', '2024-07-12 16:52:39.999999900', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999800,進(jìn)位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230012, '1', '1', '2024-08-07 16:19:23.999999800', 0, '2024-07-12 16:52:39.999999800', '2024-08-07 16:19:23.999999800', 0, '1970-01-01 00:00:00.999999800', '2024-07-12 16:52:39.999999800', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999000,截取前三位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230013, '1', '1', '2024-08-07 16:19:23.999999000', 0, '2024-07-12 16:52:39.999999000', '2024-08-07 16:19:23.999999000', 0, '1970-01-01 00:00:00.999999000', '2024-07-12 16:52:39.999999000', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999500,進(jìn)位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230014, '1', '1', '2024-08-07 16:19:23.999999500', 0, '2024-07-12 16:52:39.999999500', '2024-08-07 16:19:23.999999500', 0, '1970-01-01 00:00:00.999999500', '2024-07-12 16:52:39.999999000', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,新增操作,9個9驗證 2024-08-07 16:19:23.999999100,進(jìn)位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230015, '1', '1', '2024-08-07 16:19:23.999999100', 0, '2024-07-12 16:52:39.999999100', '2024-08-07 16:19:23.999999100', 0, '1970-01-01 00:00:00.999999100', '2024-07-12 16:52:39.999999100', -1, -1, 1);
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230016, '1', '1', '2024-08-07 16:19:23.999999200', 0, '2024-07-12 16:52:39.999999200', '2024-08-07 16:19:23.999999100', 0, '1970-01-01 00:00:00.999999100', '2024-07-12 16:52:39.999999100', -1, -1, 1);
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230017, '1', '1', '2024-08-07 16:19:23.999999300', 0, '2024-07-12 16:52:39.999999300', '2024-08-07 16:19:23.999999100', 0, '1970-01-01 00:00:00.999999100', '2024-07-12 16:52:39.999999100', -1, -1, 1);
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230018, '1', '1', '2024-08-07 16:19:23.999999400', 0, '2024-07-12 16:52:39.999999400', '2024-08-07 16:19:23.999999100', 0, '1970-01-01 00:00:00.999999100', '2024-07-12 16:52:39.999999100', -1, -1, 1);
-- 再次驗證 500 進(jìn)位
INSERT INTO crm.t_wx_user_1
(user_id, union_id, open_id, last_login_time, privacy_agreement_version, create_time, update_time, delete_flag, delete_time, first_login_time, created_by, updated_by, inst_id)
VALUES(1230019, '1', '1', '2024-08-07 16:19:23.999999500', 0, '2024-07-12 16:52:39.999999500', '2024-08-07 16:19:23.999999100', 0, '1970-01-01 00:00:00.999999100', '2024-07-12 16:52:39.999999100', -1, -1, 1);
-- postgres數(shù)據(jù)庫 timestamp類型,查詢操作,9個9驗證 2024-08-07 16:19:23.999999999,會進(jìn)位,把2024-08-07 16:19:24.000的也查詢出來。
select * from crm.t_wx_user_1 ;
where last_login_time <= '2024-08-07 16:19:23.999999999';
--截取前三位數(shù)據(jù):小于 2024-08-07 16:19:23.999999500
--進(jìn)位數(shù)據(jù):[2024-08-07 16:19:23.999999500 - 2024-08-07 16:19:23.999999999]
結(jié)論
PostgreSQL只能存儲最多6位的小數(shù)部分。因此,當(dāng)嘗試存儲超過6位的分?jǐn)?shù)秒時,會發(fā)生以下情況之一:
如果額外的數(shù)字導(dǎo)致整個分?jǐn)?shù)秒部分超過 999999 微秒,則整個時間值會進(jìn)位到下一秒,剩余的部分會被截斷或者四舍五入到 6 位小數(shù)。
在這種情況下,2024-08-07 16:19:23.999999999 會被處理為 2024-08-07 16:19:24.000000。
如果你使用的是某種客戶端或者編程語言接口來處理這個時間值,在插入之前它可能會自動進(jìn)行四舍五入或截斷。
比如:
截取前三位數(shù)據(jù):小于 2024-08-07 16:19:23.999999500
進(jìn)位數(shù)據(jù):[2024-08-07 16:19:23.999999500 - 2024-08-07 16:19:23.999999999]
-- 創(chuàng)建表
CREATE TABLE crm.wx_users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL
);
-- 插入數(shù)據(jù)
INSERT INTO crm.wx_users (name, created_at)
VALUES ('John Doe', '2024-08-07 16:19:23.999999');
INSERT INTO crm.wx_users (name, created_at)
VALUES ('Jerry', '2024-08-07 16:19:23.999996');
-- 查詢數(shù)據(jù)
SELECT * FROM crm.wx_users;
 PostgreSQL 的 timestamp 類型默認(rèn)只支持到微秒級別(6位小數(shù)),為什么select出來的數(shù)據(jù)中展示三位2024-08-07 16:19:23.999
 PostgreSQL 的 timestamp 類型確實支持到微秒級別(6位小數(shù))。然而,默認(rèn)情況下,當(dāng)您從數(shù)據(jù)庫中查詢 timestamp 值時,PostgreSQL 會將結(jié)果顯示為毫秒級別(3位小數(shù))以提高可讀性。這是默認(rèn)的行為,但是您可以更改輸出的精度。
-- 使用 to_char 函數(shù)來顯示完整的微秒
SELECT id, name, to_char(created_at, 'YYYY-MM-DD HH24:MI:SS.US') AS created_at FROM crm.wx_users;

到此這篇關(guān)于PostgreSQL數(shù)據(jù)庫timestamp數(shù)據(jù)類型精度進(jìn)位問題的文章就介紹到這了,更多相關(guān)PostgreSQL timestamp數(shù)據(jù)類型內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解決PostgreSQL服務(wù)啟動后占用100% CPU卡死的問題

    解決PostgreSQL服務(wù)啟動后占用100% CPU卡死的問題

    前文書說到,今天耗費(fèi)了九牛二虎之力,終于馴服了NTFS權(quán)限安裝好了PostgreSQL,卻不曾想,服務(wù)啟動后,新的狀況又出現(xiàn)了。
    2009-08-08
  • postgreSql分組統(tǒng)計數(shù)據(jù)的實現(xiàn)代碼

    postgreSql分組統(tǒng)計數(shù)據(jù)的實現(xiàn)代碼

    這篇文章給大家介紹postgreSql的監(jiān)控記錄表里多條不同時間的數(shù)據(jù),只取最新的數(shù)據(jù),并分組統(tǒng)計,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2020-12-12
  • 基于PostgreSQL/openGauss?的分布式數(shù)據(jù)庫解決方案

    基于PostgreSQL/openGauss?的分布式數(shù)據(jù)庫解決方案

    ShardingSphere-Proxy?作為透明數(shù)據(jù)庫代理,用戶無需關(guān)心?Proxy?如何協(xié)調(diào)背后的數(shù)據(jù)庫。今天通過本文給大家介紹基于PostgreSQL/openGauss?的分布式數(shù)據(jù)庫解決方案,感興趣的朋友跟隨小編一起看看吧
    2021-12-12
  • PostgreSQL全面查看用戶權(quán)限的方法

    PostgreSQL全面查看用戶權(quán)限的方法

    PostgreSQL查看用戶權(quán)限的全面方法,包括基本屬性、數(shù)據(jù)庫、模式、表、列、函數(shù)、序列權(quán)限,以及使用工具和內(nèi)置函數(shù)進(jìn)行綜合查詢,本文介紹PostgreSQL全面查看用戶權(quán)限的方法,感興趣的朋友跟隨小編一起看看吧
    2025-12-12
  • pgsql的UUID生成函數(shù)實例

    pgsql的UUID生成函數(shù)實例

    這篇文章主要介紹了pgsql的UUID生成函數(shù)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • postgres 使用存儲過程批量插入數(shù)據(jù)的操作

    postgres 使用存儲過程批量插入數(shù)據(jù)的操作

    這篇文章主要介紹了postgres 使用存儲過程批量插入數(shù)據(jù)的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • PostgreSQL中調(diào)用存儲過程并返回數(shù)據(jù)集實例

    PostgreSQL中調(diào)用存儲過程并返回數(shù)據(jù)集實例

    這篇文章主要介紹了PostgreSQL中調(diào)用存儲過程并返回數(shù)據(jù)集實例,本文給出一創(chuàng)建數(shù)據(jù)表、插入測試數(shù)據(jù)、創(chuàng)建存儲過程、調(diào)用創(chuàng)建存儲過程和運(yùn)行效果完整例子,需要的朋友可以參考下
    2015-01-01
  • navicat連接postgresql、人大金倉等數(shù)據(jù)庫報錯解決辦法

    navicat連接postgresql、人大金倉等數(shù)據(jù)庫報錯解決辦法

    在使用Navicat操作數(shù)據(jù)庫時,遇到數(shù)據(jù)報錯是一個常見的問題,這類問題可能涉及多個方面,下面這篇文章主要給大家介紹了關(guān)于navicat連接postgresql、人大金倉等數(shù)據(jù)庫報錯的解決辦法,需要的朋友可以參考下
    2024-08-08
  • PostgreSQL實現(xiàn)數(shù)據(jù)表跨庫同步的四種方案

    PostgreSQL實現(xiàn)數(shù)據(jù)表跨庫同步的四種方案

    文章詳細(xì)介紹了四種用于實現(xiàn)PostgreSQL數(shù)據(jù)庫表數(shù)據(jù)變化實時或定時同步到另一個獨(dú)立PG庫的方法,包括觸發(fā)器+外部表、邏輯復(fù)制、Debezium+Kafka和pg_dump定時任務(wù),針對不同場景和需求,推薦了最適合的方案,并詳細(xì)闡述了各自的優(yōu)點、適用場景、配置方法和使用注意事項
    2026-05-05
  • PostgreSQL基礎(chǔ)知識之SQL操作符實踐指南

    PostgreSQL基礎(chǔ)知識之SQL操作符實踐指南

    這篇文章主要給大家介紹了關(guān)于PostgreSQL基礎(chǔ)知識之SQL操作符實踐的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用PostgreSQL具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05

最新評論

蒙阴县| 海兴县| 维西| 临湘市| 怀柔区| 安图县| 威远县| 临江市| 汤阴县| 南阳市| 建宁县| 金溪县| 扎鲁特旗| 资兴市| 广元市| 措勤县| 安多县| 手游| 安阳县| 绥中县| 长兴县| 抚顺市| 海口市| 安福县| 昆山市| 额尔古纳市| 宁波市| 呈贡县| 犍为县| 新乡市| 武义县| 广汉市| 繁峙县| 武鸣县| 宝清县| 汝州市| 乌兰县| 内丘县| 仪陇县| 财经| 依安县|