https://www.postgresql.org/docs/current/datatype-datetime.html
可以看到Resolution timestamp , time, interval 是 1 microsecond, date 是 1 day
驗證看看
select current_timestamp
, current_timestamp(6)
, current_timestamp(0);
result:
-[ RECORD 1 ]-----+------------------------------
current_timestamp | 2023-09-27 12:52:24.202203+08
current_timestamp | 2023-09-27 12:52:24.202203+08
current_timestamp | 2023-09-27 12:52:24+08
可以看到 使用句子 current_timestamp 就可以取得,
使用函數 current_timestamp(p) 可以指定精度, p 的範圍 0 ~ 6
SELECT current_timestamp(99);
WARNING: 22023: TIMESTAMP(99) WITH TIME ZONE precision reduced to maximum allowed, 6
LOCATION: anytimestamp_typmod_check, timestamp.c:118
current_timestamp
------------------------------
2023-09-27 13:00:38.19743+08
會告訴我們使用 0~6 , 超出部分改為 6.
使用 current_timestamp() 不接受
SELECT current_timestamp();
ERROR: 42601: syntax error at or near ")"
LINE 1: SELECT current_timestamp();
^
一般我們只要使用 current_timestamp 就可以了
隨著科技的進步,目前的OS已經能度提供 nanosecond 了.
所以nanosecond extension 也登場了
https://github.com/fvannee/timestamp9
git clone https://github.com/fvannee/timestamp9.git
cd timestamp9
mkdir build
cd build
cmake ..
# or: cmake .. -DPG_CONFIG=/path/to/pg_config
make
sudo make install
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up