PostgreSQL 型別轉換

2021-10-01 09:32:59 字數 1001 閱讀 8034

0
(1 row)

在pg裡如果想做除法並想保留小數,用上面的方法卻行不通,因為"/" 運算結果為取整,並
且會截掉小數部分。

0.25

(1 row)

備註:型別轉換後,就能保留小數部分了。

0.25

(1 row)

3(1 row)

–5 附: postgresql 型別轉換函式

函式 返回型別 描述 例項

to_char(timestamp,text) text 把時間間隔轉換為字串 to_char(current_timestamp,「hh12:mi:ss」)

to_char(interval,text) text 把時間間隔轉換為字串 to_char(interval』15h 12m 12s』,『hh24:mi:ss』)

to_char(int,text) text 把整型轉換為字串 to_char(125,『999』)

to_char(double,precision) text 把實數/雙精度數轉換為字串 to_char(125.8::real,『999d9』)

to_char(numeric,text) text 把numeric轉換為字串 to_char(-125.8,『999d99s』)

to_date(text,text) date 把字串轉換為日期 to_date(『05 dec 2000』,『dd mon yyyy』)

to_timetamp(text,text) timestamp 把字串轉換為時間戳 to_timestamp(『05 dec 2000』,『dd mon yyyy』

to_timetamp(double) timestamp 把unix紀元轉換為時間戳 to_timestamp(200120400)

to_number(text,text) numeric 把字串轉換為numeric to_number(『12 454.8-』,『99g999d9s』

參考:

PostgreSQL 型別轉換

類似oracle postgresql也有強大的型別轉換函式,下面僅舉兩個型別轉換例子。1 例子 postgres select 1 4 column?0 1 row 在pg裡如果想做除法並想保留小數,用上面的方法卻行不通,因為 運算結果為取整,並 且會截掉小數部分。2 型別轉換 postgres ...

PostgreSQL 型別轉換

類似oracle postgresql也有強大的型別轉換函式,下面僅舉兩個型別轉換例子。1 例子 postgres select 1 4 column?0 1 row 在pg裡如果想做除法並想保留小數,用上面的方法卻行不通,因為 運算結果為取整,並 且會截掉小數部分。2 型別轉換 postgres ...

PostgreSQL的日誌型別

剛開始學習postgres的時候,可能對postgresql中的日誌概念比較模糊,到底有多少種日誌,哪些日誌是能刪除的,各自又記錄什麼樣的功能。postgresql中有三種日誌,pg log,pg xlog和pg clog。一.安裝路徑 這三種資料庫後兩者一般的安裝路徑是 pgdata 下面的資料夾...