系统表信息函数
format_type(type_oid, typemod)
描述:获取数据类型的SQL名称。
返回类型:text
备注:
format_type通过数据类型的类型OID以及可能的类型修饰词,返回其SQL名称。如果不知道具体的修饰词,则在类型修饰词的位置传入NULL。类型修饰词一般只对有长度限制的数据类型有意义。format_type所返回的SQL名称中包含数据类型的长度值,其大小是:实际存储长度len - sizeof(int32),单位字节。数据存储时需要32位的空间来存储用户对数据类型的自定义长度信息,即实际存储长度要比用户定义长度多4个字节。在下例中,format_type返回的SQL名称为“character varying(6)”,6表示varchar类型的长度值是6字节,因此该类型的实际存储长度为10字节。
1 2 3 4 5 |
SELECT format_type((SELECT oid FROM pg_type WHERE typname='varchar'), 10); format_type ---------------------- character varying(6) (1 row) |
pg_get_schemas(schemaPattern)
描述:查询当前catalog中的schema, 参数schemaPattern可以是具体schema名字或者用%表示的通配符。如果schemaPattern为空(使用单引号替代参数),则返回所有的schema。
返回类型:text
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
select pg_get_schemas(''); pg_get_schemas ---------------------- test_orc test1_orc test_parquet (3 row) select pg_get_schemas('%orc'); pg_get_schemas ---------------------- test_orc test1_orc (2 row) select pg_get_schemas('test_orc'); pg_get_schemas ---------------------- test_orc (1 row) |
pg_get_tables(schemaPattern, tablePattern, tableTypes)
描述:查询当前catalog中满足条件的表信息,参数schemaPattern可以指定schema名字或用%表示的通配符;参数tablePattern可以指定表名字或用%表示的通配符;tableTypes可以指定表类型。具体表类型为MANAGED_TABLE、EXTERNAL_TABLE、VIRTUAL_VIEW、 MATERIALIZED_VIEW、 DICTIONARY_TABLE这几种类型。这三个参数如果为空(使用单引号替代参数),则返回所有的catalog、schema、表名、表类型、描述信息。
返回类型:返回如下字段组成的行集。
- catalog_name
- schema_name
- table_name
- table_type
- description
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
select pg_get_tables('','',''); pg_get_tables ---------------------- (catalog,schema_parquet,table1,MANAGED_TABLE,"") (catalog,schema_parquet,table2,MANAGED_TABLE,"") (catalog,schema_orc,table1,MANAGED_TABLE,"") (3 row) select pg_get_tables('%parquet','','MANAGED_TABLE'); pg_get_tables ---------------------- (catalog,schema_parquet,table1,MANAGED_TABLE,"") (catalog,schema_parquet,table2,MANAGED_TABLE,"") (2 row) |
pg_get_columns(schemaPattern, tableNamePattern, columnNamePattern)
描述:查询当前catalog中满足条件的列信息。参数schemaPattern可以指定schema名字或用%表示的通配符;参数tableNamePattern可以指定表名字或用%表示的通配符;参数columnNamePattern可以指定列名字或用%表示的通配符。
返回类型:返回如下字段组成的行集
- catalog_name
- schema_name
- table_name
- column_name
- origintype
- atttypid
- atttypmod
- typename
- typtype
- attnum
- description
- attnotnull
- description
1 2 3 4 5 6 7 8 9 10 11 12 |
select pg_get_columns('schema_parquet','customer',''); pg_get_columns ---------------------- (catalog,schema_parquet,customer,c_custkey,bigint,20,-1,int8,b,1,,f) (catalog,schema_parquet,customer,c_name,string,25,-1,text,b,2,,f) (catalog,schema_parquet,customer,c_address,string,25,-1,text,b,3,,f) (catalog,schema_parquet,customer,c_nationkey,bigint,20,-1,int8,b,4,,f) (catalog,schema_parquet,customer,c_phone,"char(15)",1042,19,bpchar,b,5,,f) (catalog,schema_parquet,customer,c_acctbal,"decimal(15,2)",1700,983046,numeric,b,6,,f) (catalog,schema_parquet,customer,c_mktsegment,"char(10)",1042,14,bpchar,b,7,,f) (catalog,schema_parquet,customer,c_comment,string,25,-1,text,b,8,,f) (8 row) |