日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)PostgreSQL教程PostgreSQL常用函數(shù)

PostgreSQL 常用函數(shù)

PostgreSQL 內(nèi)置函數(shù)也稱為聚合函數(shù),用于對字符串或數(shù)字數(shù)據(jù)執(zhí)行處理。

10年積累的成都網(wǎng)站設(shè)計、做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有昂仁免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

下面是所有通用 PostgreSQL 內(nèi)置函數(shù)的列表:

  • COUNT 函數(shù):用于計算數(shù)據(jù)庫表中的行數(shù)。
  • MAX 函數(shù):用于查詢某一特定列中最大值。
  • MIN 函數(shù):用于查詢某一特定列中最小值。
  • AVG 函數(shù):用于計算某一特定列中平均值。
  • SUM 函數(shù):用于計算數(shù)字列所有值的總和。
  • ARRAY 函數(shù):用于輸入值(包括null)添加到數(shù)組中。
  • Numeric 函數(shù):完整列出一個 SQL 中所需的操作數(shù)的函數(shù)。
  • String 函數(shù):完整列出一個 SQL 中所需的操作字符的函數(shù)。

數(shù)學函數(shù)

下面是PostgreSQL中提供的數(shù)學函數(shù)列表,需要說明的是,這些函數(shù)中有許多都存在多種形式,區(qū)別只是參數(shù)類型不同。除非特別指明,任何特定形式的函數(shù)都返回和它的參數(shù)相同的數(shù)據(jù)類型。

函數(shù) 返回類型 描述 例子 結(jié)果
abs(x) 絕對值 abs(-17.4) 17.4
cbrt(double) 立方根 cbrt(27.0) 3
ceil(double/numeric) 不小于參數(shù)的最小的整數(shù) ceil(-42.8) -42
degrees(double) 把弧度轉(zhuǎn)為角度 degrees(0.5) 28.6478897565412
exp(double/numeric) 自然指數(shù) exp(1.0) 2.71828182845905
floor(double/numeric) 不大于參數(shù)的最大整數(shù) floor(-42.8) -43
ln(double/numeric) 自然對數(shù) ln(2.0) 0.693147180559945
log(double/numeric) 10為底的對數(shù) log(100.0) 2
log(b numeric,x numeric) numeric 指定底數(shù)的對數(shù) log(2.0, 64.0) 6.0000000000
mod(y, x) 取余數(shù) mod(9,4) 1
pi() double "π"常量 pi() 3.14159265358979
power(a double, b double) double 求a的b次冪 power(9.0, 3.0) 729
power(a numeric, b numeric) numeric 求a的b次冪 power(9.0, 3.0) 729
radians(double) double 把角度轉(zhuǎn)為弧度 radians(45.0) 0.785398163397448
random() double 0.0到1.0之間的隨機數(shù)值 random()
round(double/numeric) 圓整為最接近的整數(shù) round(42.4) 42
round(v numeric, s int) numeric 圓整為s位小數(shù)數(shù)字 round(42.438,2) 42.44
sign(double/numeric) 參數(shù)的符號(-1,0,+1) sign(-8.4) -1
sqrt(double/numeric) 平方根 sqrt(2.0) 1.4142135623731
trunc(double/numeric) 截斷(向零靠近) trunc(42.8) 42
trunc(v numeric, s int) numeric 截斷為s小數(shù)位置的數(shù)字 trunc(42.438,2) 42.43

三角函數(shù)列表

函數(shù) 描述
acos(x) 反余弦
asin(x) 反正弦
atan(x) 反正切
atan2(x, y) 正切 y/x 的反函數(shù)
cos(x) 余弦
cot(x) 余切
sin(x) 正弦
tan(x) 正切

字符串函數(shù)和操作符

下面是 PostgreSQL 中提供的字符串操作符列表:

函數(shù) 返回類型 描述 例子 結(jié)果
string || string text 字串連接 'Post' 丨丨 'greSQL' PostgreSQL
bit_length(string) int 字串里二進制位的個數(shù) bit_length('jose') 32
char_length(string) int 字串中的字符個數(shù) char_length('jose') 4
convert(string using conversion_name) text 使用指定的轉(zhuǎn)換名字改變編碼。 convert('PostgreSQL' using iso_8859_1_to_utf8) 'PostgreSQL'
lower(string) text 把字串轉(zhuǎn)化為小寫 lower('TOM') tom
octet_length(string) int 字串中的字節(jié)數(shù) octet_length('jose') 4
overlay(string placing string from int [for int]) text 替換子字串 overlay('Txxxxas' placing 'hom' from 2 for 4) Thomas
position(substring in string) int 指定的子字串的位置 position('om' in 'Thomas') 3
substring(string [from int] [for int]) text 抽取子字串 substring('Thomas' from 2 for 3) hom
substring(string from pattern) text 抽取匹配 POSIX 正則表達式的子字串 substring('Thomas' from '…$') mas
substring(string from pattern for escape) text 抽取匹配SQL正則表達式的子字串 substring('Thomas' from '%#"o_a#"_' for '#') oma
trim([leading丨trailing 丨 both] [characters] from string) text 從字串string的開頭/結(jié)尾/兩邊/ 刪除只包含characters(默認是一個空白)的最長的字串 trim(both 'x' from 'xTomxx') Tom
upper(string) text 把字串轉(zhuǎn)化為大寫。 upper('tom') TOM
ascii(text) int 參數(shù)第一個字符的ASCII碼 ascii('x') 120
btrim(string text [, characters text]) text 從string開頭和結(jié)尾刪除只包含在characters里(默認是空白)的字符的最長字串 btrim('xyxtrimyyx','xy') trim
chr(int) text 給出ASCII碼的字符 chr(65) A
convert(string text, [src_encoding name,] dest_encoding name) text 把字串轉(zhuǎn)換為dest_encoding convert( 'text_in_utf8', 'UTF8', 'LATIN1') 以ISO 8859-1編碼表示的text_in_utf8
initcap(text) text 把每個單詞的第一個子母轉(zhuǎn)為大寫,其它的保留小寫。單詞是一系列字母數(shù)字組成的字符,用非字母數(shù)字分隔。 initcap('hi thomas') Hi Thomas
length(string text) int string中字符的數(shù)目 length('jose') 4
lpad(string text, length int [, fill text]) text 通過填充字符fill(默認為空白),把string填充為長度length。 如果string已經(jīng)比length長則將其截斷(在右邊)。 lpad('hi', 5, 'xy') xyxhi
ltrim(string text [, characters text]) text 從字串string的開頭刪除只包含characters(默認是一個空白)的最長的字串。 ltrim('zzzytrim','xyz') trim
md5(string text) text 計算給出string的MD5散列,以十六進制返回結(jié)果。 md5('abc')
repeat(string text, number int) text 重復(fù)string number次。 repeat('Pg', 4) PgPgPgPg
replace(string text, from text, to text) text 把字串string里出現(xiàn)地所有子字串from替換成子字串to。 replace('abcdefabcdef', 'cd', 'XX') abXXefabXXef
rpad(string text, length int [, fill text]) text 通過填充字符fill(默認為空白),把string填充為長度length。如果string已經(jīng)比length長則將其截斷。 rpad('hi', 5, 'xy') hixyx
rtrim(string text [, character text]) text 從字串string的結(jié)尾刪除只包含character(默認是個空白)的最長的字 rtrim('trimxxxx','x') trim
split_part(string text, delimiter text, field int) text 根據(jù)delimiter分隔string返回生成的第field個子字串(1 Base)。 split_part('abc~@~def~@~ghi', '~@~', 2) def
strpos(string, substring) text 聲明的子字串的位置。 strpos('high','ig') 2
substr(string, from [, count]) text 抽取子字串。 substr('alphabet', 3, 2) ph
to_ascii(text [, encoding]) text 把text從其它編碼轉(zhuǎn)換為ASCII。 to_ascii('Karel') Karel
to_hex(number int/bigint) text 把number轉(zhuǎn)換成其對應(yīng)地十六進制表現(xiàn)形式。 to_hex(9223372036854775807) 7fffffffffffffff
translate(string text, from text, to text) text 把在string中包含的任何匹配from中的字符的字符轉(zhuǎn)化為對應(yīng)的在to中的字符。 translate('12345', '14', 'ax') a23x5

類型轉(zhuǎn)換相關(guān)函數(shù)

函數(shù) 返回類型 描述 實例
to_char(timestamp, text) text 將時間戳轉(zhuǎn)換為字符串 to_char(current_timestamp, 'HH12:MI:SS')
to_char(interval, text) text 將時間間隔轉(zhuǎn)換為字符串 to_char(interval '15h 2m 12s', 'HH24:MI:SS')
to_char(int, text) text 整型轉(zhuǎn)換為字符串 to_char(125, '999')
to_char(double precision, text) text 雙精度轉(zhuǎn)換為字符串 to_char(125.8::real, '999D9')
to_char(numeric, text) text 數(shù)字轉(zhuǎn)換為字符串 to_char(-125.8, '999D99S')
to_date(text, text) date 字符串轉(zhuǎn)換為日期 to_date('05 Dec 2000', 'DD Mon YYYY')
to_number(text, text) numeric 轉(zhuǎn)換字符串為數(shù)字 to_number('12,454.8-', '99G999D9S')
to_timestamp(text, text) timestamp 轉(zhuǎn)換為指定的時間格式 time zone convert string to time stamp to_timestamp('05 Dec 2000', 'DD Mon YYYY')
to_timestamp(double precision) timestamp 把UNIX紀元轉(zhuǎn)換成時間戳 to_timestamp(1284352323)

參考文章:https://blog.csdn.net/sun5769675/article/details/50628979


文章題目:創(chuàng)新互聯(lián)PostgreSQL教程PostgreSQL常用函數(shù)
網(wǎng)站URL:http://m.5511xx.com/article/cojhece.html