查询数据库列表:
select * from pg_database WHERE datistemplate = false;
查询组合类型:
select * from pg_type where typtype = 'c' and typarray > 0
AND typname NOT IN (SELECT TABLE_NAME FROM information_schema.tables)
order by typname
根据名称查询OID:
select 'testdbschema1.t1'::regclass::oid
根据OID查询名称:
select 16392::regclass
查询所有表:
select * from information_schema.tables where table_Catalog = 'testdb1' and table_schema='testdbschema1'
Domain:
可以基于某个基本数据类型,定义一个domain,并在这个domain上定义一个或多个check,举例:
N个表都有一个邮政编码字段,为了防止用户输入非法的邮政编码,我们需要在这个字段上定义一个check来验证用户的输入数据,显然,如果有100个表有这个字段,那么我需要定义100次这个验证规则,而且一旦规则发生变化,又需要做100次的修改
正确的做法是,定义一个domain,该domain上定义这个check,然后这100个表的邮政编码字段,都使用这个domain作为其数据类型即可:
CREATE DOMAIN testdbschema1.us_postal_code
AS text
COLLATE pg_catalog."default"
DEFAULT '000000'::text
CONSTRAINT c1 CHECK (VALUE ~ '^\d{5}$'::text OR VALUE ~ '^\d{5}-\d{4}$'::text)
CONSTRAINT c2 CHECK (VALUE IS NOT NULL);
ALTER DOMAIN testdbschema1.us_postal_code
OWNER TO testdbrole1;
COMMENT ON DOMAIN testdbschema1.us_postal_code
IS '测试domain1';
domain的default默认值:如果在列上定义了default,则覆盖domain上定义的default值,同样,如果在domain上定义了默认值,则覆盖其基础类型的默认值
查询domain列表:
select * from information_schema.domains;
查询domain的OID、OWBER、默认值:
select oid,* from pg_type where typname='us_postal_code' and typtype='d'
查询domain的备注:
select * from pg_description where objoid = 24605
查询domain的check:
select * from information_schema.domain_constraints where domain_schema = 'testdbschema1' and domain_name = 'us_postal_code'
select * from information_schema.check_constraints where constraint_schema='testdbschema1' and constraint_name = 'c1'
查询表的所有列:
select table_catalog,table_schema,table_name,column_name,ordinal_position,column_default,
is_nullable,data_type,character_maximum_length,character_octet_length,
numeric_precision,numeric_precision_radix,numeric_scale,datetime_precision,interval_type,
interval_precision,collation_catalog,collation_schema,
collation_name,domain_catalog,domain_schema,domain_name,udt_catalog,udt_schema,udt_name,dtd_identifier,
is_updatable from information_schema.Columns where table_name = 't1'
注意,列的数据类型为数组时,部分数据类型,不是存放在data_type字段中,而是存在在udt_name字段中,然后某些类型,还需要通过
select * from information_schema.element_types where object_name = 't2' or object_name = 't1' ;
查询出其显示的字面类型,比如 "_timestamp" -->"timestamp without time zone"
查询所有可用的数据类型:
系统原生态的那些类型+自定义符合类型(前面已写如何获取)+domain(前面已写如何获取)
查询表上的约束:
select * from information_schema.table_constraints
查询表上的索引:
SELECT i.relname as indname,
i.relowner as indowner,
idx.indrelid::regclass,
am.amname as indam,
idx.indkey,
ARRAY(
SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
FROM generate_subscripts(idx.indkey, 1) as k
ORDER BY k
) as indkey_names,
idx.indexprs IS NOT NULL as indexprs,
idx.indpred IS NOT NULL as indpred
FROM pg_index as idx
JOIN pg_class as i
ON i.oid = idx.indexrelid
JOIN pg_am as am
ON i.relam = am.oid
where idx.indrelid::regclass = 'testdbschema1.t1'::regclass;
相关推荐
postgre最新版本手册,数据库使用手册
Postgre SQL 9.4安装包,用于Postgre SQL的安装
postgre学习文档2
nacos_postgre.sql
Postgregis+PostGIS,开源的空数据库。
QGIS软件连接Postgre数据库截图操作
VC访问数据库有两种方法:一种是使用CDatabase和CRecord对象;另一种是利用ADO技术。 这个程序实现了Postgre数据库的读写,以及存储过程的调用。
Postgre JDBC驱动Postgre JDBC驱动Postgre JDBC驱动
设置Postgre数据库远程连接服务的两种方式,截图教程。
postgre安装文档
1. 从头开始 ...2.3. 创建新表 2.4. 向表中添加行 2.5. 查询一个表 2.6. 在表之间连接 2.7. 聚集函数 2.8. 更新 2.9. 删除 3. 高级特性 3.1. 介绍 3.2. 视图 3.3. 外键 3.4. 事务 3.5. 继承 3.6. 结论
postgre自动生成代码 ,mybatis xml dao service 这个好用,dto
net访问mysql、postgre和sqlserver
MsSql+Mysql+oracle+Postgre驱动jar包
vs调用postgre示例,使用的是vs2010,一个简单的控制台程序demo,本地运行通过
postgre8.4安装包 数据库 osm数据 之后可以打开osm格式文件
postgre最新驱动
Postgre SQL数据库安全防护.pptx
postgre数据库自动备份操作教程.pdf
易语言源码 Postgre SQL 连接池。基于 http://www.sanye.cx/?id=12020 的源码 二次开发...封装了一些高级方法..包括,连接池+查询缓存+不知道真假的储存过程+慢查询记录。使用源码使用了E2EE支持库(模块部分思路借鉴...