暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Opengauss SQL函数介绍

是赐赐啊!🦄 2024-10-31
249


一、常用SQL函数

1、字符串函数

  • concat(str1,str2)

描述:将字符串str1和str2连接并返回。

返回值:

vcentrex=> select concat('hello',' world');

concat

-------------

hello world

(1 row)

vcentrex=> select concat('hello',NULL);

concat

--------

(1 row)

数据库SQL兼容模式设置为MY的情况下,参数str1或str2为NULL会导致返回结果为NULL。

openGauss=# select concat('hello',NULL);

concat

--------

hello

(1 row)

openGauss=#

string || string

描述:连接字符串。

返回值类型:text

openGauss=# SELECT 'MPP'||'DB' AS RESULT;

result

--------

MPPDB

(1 row)

  • concat_ws(sep text, str"any" [, str"any" [, …] ])

描述:以第一个参数为分隔符,链接第二个以后的所有参数。NULL参数被忽略。

返回值类型:text

openGauss=# SELECT concat_ws(',', 'ABCDE', 2, NULL, 22);

concat_ws

------------

ABCDE,2,22

(1 row)

  • replace(string varchar, search_string varchar, replacement_string varchar)

描述:把字符串string中所有子字符串search_string替换成子字符串replacement_string。

返回值类型:varchar

openGauss=# SELECT replace('jack and jue','j','bl');

replace

----------------

black and blue

(1 row)

  • instr(string,substring[,position,occurrence])

描述:从字符串string的position(缺省时为1)所指的位置开始查找并返回第occurrence(缺省时为1)次出现子串substring的位置的值。

当position为0时,返回0。

当position为负数时,从字符串倒数第n个字符往前逆向搜索。n为position的绝对值。

返回值类型:integer

openGauss=# SELECT instr('corporate floor','or', 3);

instr

-------

5

(1 row)

openGauss=# SELECT instr('corporate floor','or',-3,2);

instr

-------

2

(1 row)

  • find_in_set(text, set)

描述:查找给定成员在集合中的位置,从1开始计数。如果没有找到,返回0。

返回值类型:int2

openGauss=# select site, find_in_set('wuhan', site) from employee;

site | find_in_set

-----------------+-------------

beijing,nanjing | 0

beijing,wuhan | 2

(2 rows)

  • trim([leading |trailing |both] [characters] from string)

描述:从字符串string的开头、结尾或两边删除只包含characters中字符(缺省是一个空白)的最长的字符串。

返回值类型:text

openGauss=# SELECT trim(BOTH 'x' FROM 'xTomxx');

btrim

-------

Tom

(1 row)

openGauss=# SELECT trim(LEADING 'x' FROM 'xTomxx');

ltrim

-------

Tomxx

(1 row)

openGauss=# SELECT trim(TRAILING 'x' FROM 'xTomxx');

rtrim

-------

xTom

(1 row)

btrim(string text [, characters text])

描述:从string开头和结尾删除只包含characters中字符(缺省是空白)的最长字符串。

返回值类型:text

openGauss=# SELECT btrim('XXsringX' , 'X');

btrim

-------

sring

(1 row)

rtrim(string [, characters])

描述:从字符串string的结尾删除只包含characters中字符(缺省是个空白)的最长的字符串。

返回值类型:text

openGauss=# SELECT rtrim('TRIMxxxx','x');

rtrim

-------

TRIM

(1 row)

ltrim(string [, characters])

描述:从字符串string的开头删除只包含characters中字符(缺省是一个空白)的最长的字符串。

返回值类型:text

openGauss=# SELECT ltrim('xxxxTRIM','x');

ltrim

-------

TRIM

(1 row)

substr(string,from)

描述:

从参数string中抽取子字符串。

from表示抽取的起始位置。

from为0时,按1处理。

from为正数时,抽取从from到末尾的所有字符。

from为负数时,抽取字符串的后n个字符,n为from的绝对值。

返回值类型:varchar

openGauss=# SELECT substr('ABCDEF',2);

substr

--------

BCDEF

(1 row)

openGauss=# SELECT substr('ABCDEF',-2);

substr

--------

EF

(1 row)

substr(string,from,count)

描述:

从参数string中抽取子字符串。

from表示抽取的起始位置。

from为0时,按1处理。

from为正数时,抽取从from开始的count个字符。

from为负数时,抽取从倒数第n个开始的count个字符,n为from的绝对值。

count表示抽取的子字符串长度。

count小于1时,返回null。

返回值类型:varchar

openGauss=# SELECT substr('ABCDEF',2,2);

substr

--------

BC

(1 row)

openGauss=# SELECT substr('ABCDEF',-3,2);

substr

--------

DE

(1 row)

length(string)

描述:获取参数string中字符的数目。

返回值类型:integer

openGauss=# SELECT length('abcd');

length

--------

4

(1 row)

strpos(string, substring)

描述:指定的子字符串的位置。和position(substring in string)一样,不过参数顺序相反。

返回值类型:int

openGauss=# SELECT strpos('source', 'rc');

strpos

--------

4

(1 row)

reverse(str)

描述:返回颠倒的字符串。

返回值类型:text

openGauss=# SELECT reverse('abcde');

reverse

---------

edcba

(1 row)

2、数字函数

ceil(x)

描述:不小于参数的最小的整数。

返回值类型:整数。

openGauss=# SELECT ceil(-42.8);

ceil

------

-42

(1 row)

floor(x)

描述:不大于参数的最大整数。

返回值类型:与输入相同。

openGauss=# SELECT floor(-42.8);

floor

-------

-43

(1 row)

random()

描述:0.0到1.0之间的随机数。

返回值类型:double precision

openGauss=# SELECT random();

random

------------------

.824823560658842

(1 row)

mod(x,y)

描述:x/y的余数(模)。如果x是0,则返回0。

返回值类型:与参数类型相同。

openGauss=# SELECT mod(9,4);

mod

-----

1

(1 row)

openGauss=# SELECT mod(9,0);

mod

-----

9

(1 row)

openGauss=# SELECT mod(0,4);

mod

-----

0

(1 row)

round(x)

描述:离输入参数最近的整数。

返回值类型:与输入相同。

openGauss=# SELECT round(42.4);

round

-------

42

(1 row)

openGauss=# SELECT round(42.6);

round

-------

43

(1 row)

trunc(x)

描述:截断(取整数部分)。

返回值类型:与输入相同。

openGauss=# SELECT trunc(42.8);

trunc

-------

42

(1 row)

trunc(v numeric, s int)

描述:截断为s位小数。

返回值类型:numeric

openGauss=# SELECT trunc(42.4382, 2);

trunc

-------

42.43

(1 row)

3、日期函数

age(timestamp, timestamp)

描述:将两个参数相减,并以年、月、日作为返回值。若相减值为负,则函数返回亦为负,入参可以都带timezone或都不带timezone。

返回值类型:interval

openGauss=# SELECT age(timestamp '2001-04-10', timestamp '1957-06-13');

age

-------------------------

43 years 9 mons 27 days

(1 row)

age(timestamp)

描述:当前时间和参数相减,入参可以带或者不带timezone。

返回值类型:interval

openGauss=# SELECT age(timestamp '1957-06-13');

age

-------------------------

60 years 2 mons 18 days

(1 row)

current_date

描述:当前日期。

返回值类型:date

openGauss=# SELECT current_date;

date

------------

2023-05-17

(1 row)

current_time

描述:当前时间。

返回值类型:time with time zone

openGauss=# SELECT current_time;

timetz

-------------------

15:05:33.75556+08

(1 row)

current_timestamp

描述:当前日期及时间。

返回值类型:timestamp with time zone

openGauss=# SELECT current_timestamp;

pg_systimestamp

-------------------------------

2023-05-17 15:06:04.223968+08

(1 row)

date_part(text, timestamp)

描述:获取日期/时间值中子域的值,例如年或者小时的值。等效于extract(field from timestamp)。

timestamp类型:abstime、date、interval、reltime、time with time zone、time without time zone、timestamp with time zone、timestamp without time zone。

返回值类型:double precision

openGauss=# SELECT date_part('hour', timestamp '2001-02-16 20:38:40');

date_part

-----------

20

(1 row)

openGauss=# SELECT date_part('day', TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

16

(1 row)

extract(field from timestamp)

描述:extract函数从日期或时间的数值里抽取子域,比如年、小时等。source必须是一个timestamp、time或interval类型的值表达式(类型为date的表达式转换为timestamp,因此也可以用)。field是一个标识符或者字符串,它指定从源数据中抽取的域。

返回值类型:double precision

openGauss=# SELECT extract(hour from timestamp '2001-02-16 20:38:40');

date_part

-----------

20

(1 row)

openGauss=# SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

16

(1 row)

openGauss=# SELECT EXTRACT(DAY FROM INTERVAL '40 days 1 minute');

date_part

-----------

40

(1 row)

DOW:每周的星期几,星期天(0)到星期六(6)。

openGauss=# SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

5

(1 row)

一周的第几天(1-7)。

星期一为1,星期天为7。

除了星期天外,都与dow相同。

openGauss=# SELECT EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');

date_part

-----------

7

(1 row)

DOY:一年的第几天(1~365/366)。

openGauss=# SELECT EXTRACT(DOY FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

47

(1 row)

date_part

openGauss=# SELECT EXTRACT(MINUTE FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

38

(1 row)

openGauss=# SELECT EXTRACT(MONTH FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

2

(1 row)

openGauss=# SELECT EXTRACT(MONTH FROM INTERVAL '2 years 13 months');

date_part

-----------

1

(1 row)

openGauss=# SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

1

(1 row)

openGauss=# SELECT EXTRACT(WEEK FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

7

(1 row)

openGauss=# SELECT EXTRACT(YEAR FROM TIMESTAMP '2001-02-16 20:38:40');

date_part

-----------

2001

(1 row)

date_trunc(text, timestamp)

描述:截取到参数text指定的精度。

返回值类型:interval、timestamp with time zone、timestamp without time zone

openGauss=# SELECT date_trunc('hour', timestamp '2001-02-16 20:38:40');

date_trunc

---------------------

2001-02-16 20:00:00

(1 row)

openGauss=# SELECT date_trunc('hour', current_timestamp);

date_trunc

------------------------

2023-05-17 15:00:00+08

(1 row)

openGauss=# SELECT date_trunc('day', current_timestamp);

date_trunc

------------------------

2023-05-17 00:00:00+08

(1 row)

openGauss=# SELECT date_trunc('month', current_timestamp);

date_trunc

------------------------

2023-05-01 00:00:00+08

(1 row)

trunc(timestamp)

描述:默认按天截取。

openGauss=# SELECT trunc(current_timestamp);

trunc

---------------------

2023-05-17 00:00:00

(1 row)

isfinite(date)

描述:测试是否为有效日期。

返回值类型:Boolean

openGauss=# SELECT isfinite(date '2001-02-16');

isfinite

----------

t

(1 row)

isfinite(timestamp)

描述:测试判断是否为有效时间。

返回值类型:Boolean

openGauss=# SELECT isfinite(timestamp '2001-02-16 21:28:30');

isfinite

----------

t

(1 row)

now()

描述:当前日期及时间。

返回值类型:timestamp with time zone

openGauss=# select now();

now

-------------------------------

2023-05-17 15:38:39.232597+08

(1 row)

sysdate

描述:当前日期及时间。

返回值类型:timestamp

openGauss=# select sysdate;

sysdate

---------------------

2023-05-17 15:40:06

(1 row)

add_months(d,n)

描述:用于计算时间点d再加上n个月的时间。

d:timestamp类型的值,以及可以隐式转换为timestamp类型的值。

n:INTEGER类型的值,以及可以隐式转换为INTEGER类型的值。

返回值类型:timestamp

openGauss=# SELECT add_months(sysdate, 11);

add_months

---------------------

2024-04-17 15:41:25

(1 row)

last_day(d)

描述:用于计算时间点d当月最后一天的时间。

返回值类型:timestamp

openGauss=# select last_day(sysdate) AS cal_result;

cal_result

---------------------

2023-05-31 15:42:33

(1 row)

openGauss=# select last_day(current_date) AS cal_result;

cal_result

---------------------

2023-05-31 00:00:00

(1 row)

next_day(x,y)

描述:用于计算时间点x开始的下一个星期几(y)的时间。

返回值类型:timestamp

openGauss=# select next_day(sysdate,'Sunday')AS cal_result;

cal_result

---------------------

2023-05-21 15:44:26

(1 row)

TIMESTAMPDIFF(unit , timestamp_expr1, timestamp_expr2)

timestampdiff函数是计算两个日期时间之间(timestamp_expr2-timestamp_expr1)的差值,并以unit形式返回结果。timestamp_expr1,timestamp_expr2必须是一个timestamp、timestamptz、date类型的值表达式。unit表示的是两个日期差的单位。

openGauss=# SELECT TIMESTAMPDIFF(YEAR, '2018-01-01', '2020-01-01');

timestamp_diff

----------------

2

(1 row)

openGauss=# SELECT TIMESTAMPDIFF(QUARTER, '2018-01-01', '2020-01-01');

timestamp_diff

----------------

8

(1 row)

openGauss=# SELECT TIMESTAMPDIFF(MONTH, '2018-01-01', '2020-01-01');

timestamp_diff

----------------

24

(1 row)

openGauss=# SELECT TIMESTAMPDIFF(WEEK, '2018-01-01', '2020-01-01');

timestamp_diff

----------------

104

(1 row)

openGauss=# SELECT TIMESTAMPDIFF(DAY, '2018-01-01', '2020-01-01');

timestamp_diff

----------------

730

(1 row)

openGauss=# SELECT TIMESTAMPDIFF(HOUR, '2020-01-01 10:10:10', '2020-01-01 11:11:11');

timestamp_diff

----------------

1

(1 row)

openGauss=# SELECT TIMESTAMPDIFF(MINUTE, '2020-01-01 10:10:10', '2020-01-01 11:11:11');

timestamp_diff

----------------

61

(1 row)

openGauss=# SELECT TIMESTAMPDIFF(SECOND, '2020-01-01 10:10:10', '2020-01-01 11:11:11');

timestamp_diff

----------------

3661

(1 row)

4、类型转换函数

to_char(datetime/interval [, fmt])

描述:将一个DATE、TIMESTAMP、TIMESTAMP WITH TIME ZONE或者TIMESTAMP WITH LOCAL TIME ZONE类型的DATETIME或者INTERVAL值按照fmt指定的格式转换为TEXT类型。

可选参数fmt可以为:HH24、MI、SS、YYYY、MM、DD。

openGauss=# SELECT to_char(current_timestamp, 'YYYYMMDDHH24MISS');

to_char

----------------

20230517164519

(1 row)

openGauss=# SELECT to_char(current_timestamp, 'HH24:MI:SS');

to_char

----------

10:41:26

(1 row)

to_date(text)

描述:将文本类型的值转换为指定格式的时间戳。目前只支持两类格式。

格式一:无分隔符日期,如20150814,需要包括完整的年月日。

格式二:带分隔符日期,如2014-08-14,分隔符可以是单个任意非数字字符。

返回值类型:timestamp without time zone

openGauss=# SELECT to_date('20230514');

to_date

---------------------

2023-05-14 00:00:00

(1 row)

openGauss=# SELECT to_date('20230514010000');

to_date

---------------------

2023-05-14 01:00:00

(1 row)

openGauss=# SELECT to_date('2023-05-14');

to_date

---------------------

2023-05-14 00:00:00

(1 row)

cast(x as y)

描述:类型转换函数,将x转换成y指定的类型。

openGauss=# SELECT cast('22-oct-1997' as timestamp);

timestamp

---------------------

1997-10-22 00:00:00

(1 row)

5、条件表达式函数

decode(base_expr, compare1, value1, Compare2,value2, … default)

描述:把base_expr与后面的每个compare(n) 进行比较,如果匹配返回相应的value(n)。如果没有发生匹配,则返回default。

openGauss=# SELECT decode('A','A',1,'B',2,0);

case

------

1

(1 row)

sfdb=# select sum(decode(kind,'0',1,0)) kind0 from dwh_servicealert;

kind0

-------

48

(1 row)

Case when ……then……

When ……then ……

Else ……

End

二、其他系统函数

1、系统信息函数

current_database()

openGauss=# SELECT current_database();

current_database

------------------

postgres

(1 row)

current_schema()

openGauss=# SELECT current_schema();

current_schema

----------------

public

(1 row)

current_user

openGauss=# SELECT current_user;

current_user

--------------

omm

(1 row)

pg_current_sessionid()

openGauss=# SELECT pg_current_sessionid();

pg_current_sessionid

----------------------------

1684389710.140181399860992

(1 row)

pg_current_sessid()

openGauss=# select pg_current_sessid();

pg_current_sessid

-------------------

140181399860992

(1 row)

pg_postmaster_start_time()

openGauss=# SELECT pg_postmaster_start_time();

pg_postmaster_start_time

-------------------------------

2023-04-26 16:57:16.319653+08

(1 row)

Version()

openGauss=# select version();

version

------------------------------------------------------------------------------------------------------------------------------------------------------

(openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:09:38 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit

(1 row)

openGauss=#

opengauss_version();

openGauss=# select opengauss_version();

opengauss_version

-------------------

5.0.0

(1 row)

get_hostname()

openGauss=# SELECT get_hostname();

get_hostname

--------------

eb3316

(1 row)

get_nodename()

openGauss=# SELECT get_nodename();

get_nodename

-------------------

dn_6001_6002_6003

(1 row)

2、数据库对象函数

pg_get_tabledef(table_name)

描述:根据table_name获取表定义。

vcentrex=> select * from pg_get_tabledef('ctx_callrecordlog');

pg_get_tabledef

--------------------------------------------------------------------------------------------------------------

SET search_path = vcentrex; +

CREATE TABLE ctx_callrecordlog ( +

streamnumber bigint DEFAULT nextval('ctx_callrecordlog_streamnumber_seq'::regclass) NOT NULL, +

icid character varying(75) DEFAULT NULL::character varying, +

origcallingpartynum character varying(75) DEFAULT NULL::character varying, +

origcalledpartynum character varying(75) DEFAULT NULL::character varying, +

callingpartynum character varying(75) DEFAULT NULL::character varying, +

calledpartynum character varying(75) DEFAULT NULL::character varying, +

callsuccflag character(1) DEFAULT NULL::bpchar, +

recvinvitetime character varying(14) DEFAULT NULL::character varying, +

callbegintime character varying(14) DEFAULT NULL::character varying, +

callendtime character varying(14) NOT NULL, +

role_of_node character(1) DEFAULT NULL::bpchar, +

duration integer, +

phonenumber character varying(30) DEFAULT NULL::character varying, +

urihost character varying(40) DEFAULT NULL::character varying, +

remotephonenum character varying(30) DEFAULT NULL::character varying, +

errorcode smallint, +

recvringingtime character varying(14) DEFAULT NULL::character varying, +

ringingduration integer, +

recvbyetime character varying(14) DEFAULT NULL::character varying, +

callansduration integer, +

callduration integer, +

vpncode character varying(16) DEFAULT NULL::character varying, +

calldescription integer +

) +

WITH (orientation=row, compression=no) +

PARTITION BY RANGE (callendtime) +

( +

PARTITION p20200401000000 VALUES LESS THAN ('20200402000000') TABLESPACE pg_default, +

PARTITION p20200402000000 VALUES LESS THAN ('20200403000000') TABLESPACE pg_default, +

PARTITION p20200403000000 VALUES LESS THAN ('20200404000000') TABLESPACE pg_default, +

PARTITION p20200404000000 VALUES LESS THAN ('20200405000000') TABLESPACE pg_default, +

PARTITION p20200405000000 VALUES LESS THAN ('20200406000000') TABLESPACE pg_default, +

PARTITION p20200406000000 VALUES LESS THAN ('20200407000000') TABLESPACE pg_default, +

PARTITION p20200407000000 VALUES LESS THAN ('20200408000000') TABLESPACE pg_default, +

PARTITION p20200408000000 VALUES LESS THAN ('20200409000000') TABLESPACE pg_default, +

PARTITION p20200409000000 VALUES LESS THAN ('20200410000000') TABLESPACE pg_default, +

PARTITION p20200410000000 VALUES LESS THAN ('20200411000000') TABLESPACE pg_default, +

PARTITION p20200411000000 VALUES LESS THAN ('20200412000000') TABLESPACE pg_default, +

PARTITION p20200412000000 VALUES LESS THAN ('20200413000000') TABLESPACE pg_default, +

PARTITION p20200413000000 VALUES LESS THAN ('20200414000000') TABLESPACE pg_default, +

PARTITION p20200414000000 VALUES LESS THAN ('20200415000000') TABLESPACE pg_default, +

PARTITION p20200415000000 VALUES LESS THAN ('20200416000000') TABLESPACE pg_default, +

PARTITION p20200416000000 VALUES LESS THAN ('20200417000000') TABLESPACE pg_default, +

PARTITION p20200417000000 VALUES LESS THAN ('20200418000000') TABLESPACE pg_default, +

PARTITION p20200418000000 VALUES LESS THAN ('20200419000000') TABLESPACE pg_default, +

PARTITION p20200419000000 VALUES LESS THAN ('20200420000000') TABLESPACE pg_default, +

PARTITION p20200420000000 VALUES LESS THAN ('20200421000000') TABLESPACE pg_default, +

PARTITION p20200421000000 VALUES LESS THAN ('20200422000000') TABLESPACE pg_default, +

PARTITION p20200422000000 VALUES LESS THAN ('20200423000000') TABLESPACE pg_default, +

PARTITION p20200423000000 VALUES LESS THAN ('20200424000000') TABLESPACE pg_default, +

PARTITION p20200424000000 VALUES LESS THAN ('20200425000000') TABLESPACE pg_default, +

PARTITION p20200425000000 VALUES LESS THAN ('20200426000000') TABLESPACE pg_default, +

PARTITION p20200426000000 VALUES LESS THAN ('20200427000000') TABLESPACE pg_default, +

PARTITION p20200427000000 VALUES LESS THAN ('20200428000000') TABLESPACE pg_default, +

PARTITION p20200428000000 VALUES LESS THAN ('20200429000000') TABLESPACE pg_default, +

PARTITION p20200429000000 VALUES LESS THAN ('20200430000000') TABLESPACE pg_default, +

PARTITION p20200430000000 VALUES LESS THAN ('20200501000000') TABLESPACE pg_default, +

PARTITION pm VALUES LESS THAN (MAXVALUE) TABLESPACE pg_default +

) +

ENABLE ROW MOVEMENT; +

CREATE INDEX ctx_callrecordlog_idx1 ON ctx_callrecordlog USING btree (callendtime) TABLESPACE pg_default; +

ALTER TABLE ctx_callrecordlog ADD CONSTRAINT ctx_callrecordlog_pkey PRIMARY KEY (streamnumber, callendtime);

(1 row)

vcentrex=>

pg_get_viewdef(view_name)

描述:为视图获取底层的SELECT命令。

返回类型:text

pg_database_size(name)

描述:指定名称的数据库使用的磁盘空间。

返回值类型:bigint

sfdb=# SELECT pg_database_size('sfdb');

pg_database_size

------------------

41470657

(1 row)

pg_relation_size(text)

描述:指定名称的表或者索引使用的磁盘空间。表名称可以用模式名修饰。

返回值类型:bigint

sfdb=# select pg_relation_size('dim_date');

pg_relation_size

------------------

909312

(1 row)

sfdb=# select pg_relation_size('idx_d_1');

pg_relation_size

------------------

122880

(1 row)

pg_table_size(regclass)

描述:指定的表使用的磁盘空间,不计索引(但是包含TOAST,自由空间映射和可见性映射)。

返回值类型:bigint

sfdb=# select pg_table_size('dim_date');

pg_table_size

---------------

933888

(1 row)

pg_partition_size(text, text)

描述:指定名称的分区使用的磁盘空间。其中,第一个text为表名,第二个text为分区名。

返回值类型:bigint

select pg_partition_size('ctx_callrecordlog', 'p20200421000000')

pg_partition_indexes_size(text,text)

描述:指定名称的分区的索引使用的磁盘空间。其中,第一个text为表名,第二个text为分区名。

返回值类型:bigint

pg_tablespace_size(name)

描述:指定名称的表空间使用的磁盘空间。

返回值类型:bigint

sfdb=# select pg_tablespace_size('pg_default');

pg_tablespace_size

--------------------

346123150

(1 row)

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论