postgreSQL常用函式

2021-06-19 21:06:22 字數 1462 閱讀 6162

select coalesce( sum(duration) , 0)--若sum(duration)返回值為空,則為其賦值0

select to_date('2013-12-20','yyyy-mm-dd') --字串轉化為date型別

select (date '2013-10-28 01:00' - interval '50 minutes'|| ' ')--字串的拼接

select to_char( current_date, 'yyyy-mm-dd')--時間型別轉為為字串

select extract(hour from timestamp '2013-10-28 01:00' - interval '1 days' ) --獲取一天前小時值

select extract(hour from current_time - interval '3 hours' ) --獲取三個小時前的小時

v_day_start := select to_char( current_date, 'yyyy-mm-dd')--賦值加型別轉換

select date_part('epoch', timestamp '2013-11-28 11:00'- timestamp '2013-11-28 01:30' ); --將時間差轉變為秒數

select sum(duration) from engine_test where state_start >='2013-12-12 12:30' and state_stop <'2013-12-12 14:30' and station='gcic_tc01'

select date_part('epoch', timestamp '2013-11-28 01:00'- timestamp '2013-11-27 17:30' ); --把時間差轉化為秒

select 23+23 --數值計算

v_runtime := v_starttime_interval + v_runningtime + v_endtime_interval --儲存過程中的賦值加減操作

select state_stop - '2013-12-12 12:30' from engine_test

where state_start <= '2013-12-12 12:30' and state_stop > '2013-12-12 12:30'

and type = 1 and station='gcic_' || 'tc02';--時間型別的計算

select coalesce( sum(duration) , 0) from engine_test where station = 'gcic_' || i_station --根據傳入的引數i_station進行拼接字串拼接,然後作為查詢條件來使用

and createdon >= '2013-12-12 10:30'

and createdon < '2013-12-12 12:30';

postgresql常用函式

create table search.t test 20200108 c id varchar 300 c field varchar 300 insert into search.t test 20200108 values 1 醫療器械類,化妝品類,藥品類,食品類 concat ws第乙個引數...

常用PostgreSQL函式

1.數學函式abs 返回絕對值 pi 返回圓周率值 sqrt 返回非負數的二次方根 mod x,y 返回x被y除 x y 後的餘數,x也可以為小數 ceil x 或 ceiling x 返回不小於x最小整數值 floor x 返回不大於x的最大整數值 round x 返回最接近於x的整數 round...

postgresql 常用小函式

將字串按照分隔符劃分成為陣列 create or replace function tools str2array in originstr varchar 800 in delimeter varchar 10 returns varchar 800 as declare strres varch...