information_schema.sql
来自「PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统」· SQL 代码 · 共 1,725 行 · 第 1/5 页
SQL
1,725 行
/* * SQL Information Schema * as defined in ISO 9075-2:1999 chapter 20 * * Copyright (c) 2003-2005, PostgreSQL Global Development Group * * $PostgreSQL: pgsql/src/backend/catalog/information_schema.sql,v 1.31 2005/10/02 23:50:07 tgl Exp $ *//* * Note: Generally, the definitions in this file should be ordered * according to the clause numbers in the SQL standard, which is also the * alphabetical order. In some cases it is convenient or necessary to * define one information schema view by using another one; in that case, * put the referencing view at the very end and leave a note where it * should have been put. *//* * 20.2 * INFORMATION_SCHEMA schema */CREATE SCHEMA information_schema;GRANT USAGE ON SCHEMA information_schema TO PUBLIC;SET search_path TO information_schema, public;/* * A few supporting functions first ... *//* Expand any 1-D array into a set with integers 1..N */CREATE FUNCTION _pg_expandarray(IN anyarray, OUT x anyelement, OUT n int) RETURNS SETOF RECORD LANGUAGE sql STRICT IMMUTABLE AS 'select $1[s], s - pg_catalog.array_lower($1,1) + 1 from pg_catalog.generate_series(pg_catalog.array_lower($1,1), pg_catalog.array_upper($1,1), 1) as g(s)';CREATE FUNCTION _pg_keyissubset(smallint[], smallint[]) RETURNS boolean LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS 'select $1[1] is null or ($1[1] = any ($2) and coalesce(information_schema._pg_keyissubset($1[2:pg_catalog.array_upper($1,1)], $2), true))';CREATE FUNCTION _pg_keysequal(smallint[], smallint[]) RETURNS boolean LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS 'select information_schema._pg_keyissubset($1, $2) and information_schema._pg_keyissubset($2, $1)';CREATE FUNCTION _pg_truetypid(pg_attribute, pg_type) RETURNS oid LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE WHEN $2.typtype = 'd' THEN $2.typbasetype ELSE $1.atttypid END$$;CREATE FUNCTION _pg_truetypmod(pg_attribute, pg_type) RETURNS int4 LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE WHEN $2.typtype = 'd' THEN $2.typtypmod ELSE $1.atttypmod END$$;-- these functions encapsulate knowledge about the encoding of typmod:CREATE FUNCTION _pg_char_max_length(typid oid, typmod int4) RETURNS integer LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE WHEN $2 = -1 /* default typmod */ THEN null WHEN $1 IN (1042, 1043) /* char, varchar */ THEN $2 - 4 WHEN $1 IN (1560, 1562) /* bit, varbit */ THEN $2 ELSE null END$$;CREATE FUNCTION _pg_char_octet_length(typid oid, typmod int4) RETURNS integer LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE WHEN $1 IN (25, 1042, 1043) /* text, char, varchar */ THEN CAST(2^30 AS integer) ELSE null END$$;CREATE FUNCTION _pg_numeric_precision(typid oid, typmod int4) RETURNS integer LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE $1 WHEN 21 /*int2*/ THEN 16 WHEN 23 /*int4*/ THEN 32 WHEN 20 /*int8*/ THEN 64 WHEN 1700 /*numeric*/ THEN CASE WHEN $2 = -1 THEN null ELSE (($2 - 4) >> 16) & 65535 END WHEN 700 /*float4*/ THEN 24 /*FLT_MANT_DIG*/ WHEN 701 /*float8*/ THEN 53 /*DBL_MANT_DIG*/ ELSE null END$$;CREATE FUNCTION _pg_numeric_precision_radix(typid oid, typmod int4) RETURNS integer LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE WHEN $1 IN (21, 23, 20, 700, 701) THEN 2 WHEN $1 IN (1700) THEN 10 ELSE null END$$;CREATE FUNCTION _pg_numeric_scale(typid oid, typmod int4) RETURNS integer LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE WHEN $1 IN (21, 23, 20) THEN 0 WHEN $1 IN (1700) THEN CASE WHEN $2 = -1 THEN null ELSE ($2 - 4) & 65535 END ELSE null END$$;CREATE FUNCTION _pg_datetime_precision(typid oid, typmod int4) RETURNS integer LANGUAGE sql IMMUTABLE RETURNS NULL ON NULL INPUT AS$$SELECT CASE WHEN $2 = -1 /* default typmod */ THEN null WHEN $1 IN (1083, 1114, 1184, 1266) /* time, timestamp, same + tz */ THEN $2 WHEN $1 IN (1186) /* interval */ THEN $2 & 65535 ELSE null END$$;-- 20.3 INFORMATION_SCHEMA_CATALOG_NAME view appears later./* * 20.4 * CARDINAL_NUMBER domain */CREATE DOMAIN cardinal_number AS integer CONSTRAINT cardinal_number_domain_check CHECK (value >= 0);/* * 20.5 * CHARACTER_DATA domain */CREATE DOMAIN character_data AS character varying;/* * 20.6 * SQL_IDENTIFIER domain */CREATE DOMAIN sql_identifier AS character varying;/* * 20.3 * INFORMATION_SCHEMA_CATALOG_NAME view */CREATE VIEW information_schema_catalog_name AS SELECT CAST(current_database() AS sql_identifier) AS catalog_name;GRANT SELECT ON information_schema_catalog_name TO PUBLIC;/* * 20.7 * TIME_STAMP domain */CREATE DOMAIN time_stamp AS timestamp(2) DEFAULT current_timestamp(2);/* * 20.9 * APPLICABLE_ROLES view */CREATE VIEW applicable_roles AS SELECT CAST(a.rolname AS sql_identifier) AS grantee, CAST(b.rolname AS sql_identifier) AS role_name, CAST(CASE WHEN m.admin_option THEN 'YES' ELSE 'NO' END AS character_data) AS is_grantable FROM pg_auth_members m JOIN pg_authid a ON (m.member = a.oid) JOIN pg_authid b ON (m.roleid = b.oid) WHERE pg_has_role(a.oid, 'MEMBER');GRANT SELECT ON applicable_roles TO PUBLIC;/* * 20.13 * CHECK_CONSTRAINTS view */CREATE VIEW check_constraints AS SELECT CAST(current_database() AS sql_identifier) AS constraint_catalog, CAST(rs.nspname AS sql_identifier) AS constraint_schema, CAST(con.conname AS sql_identifier) AS constraint_name, CAST(substring(pg_get_constraintdef(con.oid) from 7) AS character_data) AS check_clause FROM pg_constraint con LEFT OUTER JOIN pg_namespace rs ON (rs.oid = con.connamespace) LEFT OUTER JOIN pg_class c ON (c.oid = con.conrelid) LEFT OUTER JOIN pg_type t ON (t.oid = con.contypid) WHERE pg_has_role(coalesce(c.relowner, t.typowner), 'MEMBER') AND con.contype = 'c';GRANT SELECT ON check_constraints TO PUBLIC;/* * 20.15 * COLUMN_DOMAIN_USAGE view */CREATE VIEW column_domain_usage AS SELECT CAST(current_database() AS sql_identifier) AS domain_catalog, CAST(nt.nspname AS sql_identifier) AS domain_schema, CAST(t.typname AS sql_identifier) AS domain_name, CAST(current_database() AS sql_identifier) AS table_catalog, CAST(nc.nspname AS sql_identifier) AS table_schema, CAST(c.relname AS sql_identifier) AS table_name, CAST(a.attname AS sql_identifier) AS column_name FROM pg_type t, pg_namespace nt, pg_class c, pg_namespace nc, pg_attribute a WHERE t.typnamespace = nt.oid AND c.relnamespace = nc.oid AND a.attrelid = c.oid AND a.atttypid = t.oid AND t.typtype = 'd' AND c.relkind IN ('r', 'v') AND a.attnum > 0 AND NOT a.attisdropped AND pg_has_role(t.typowner, 'MEMBER');GRANT SELECT ON column_domain_usage TO PUBLIC;/* * 20.16 * COLUMN_PRIVILEGES */CREATE VIEW column_privileges AS SELECT CAST(u_grantor.rolname AS sql_identifier) AS grantor, CAST(grantee.rolname AS sql_identifier) AS grantee, CAST(current_database() AS sql_identifier) AS table_catalog, CAST(nc.nspname AS sql_identifier) AS table_schema, CAST(c.relname AS sql_identifier) AS table_name, CAST(a.attname AS sql_identifier) AS column_name, CAST(pr.type AS character_data) AS privilege_type, CAST( CASE WHEN aclcontains(c.relacl, makeaclitem(grantee.oid, u_grantor.oid, pr.type, true)) THEN 'YES' ELSE 'NO' END AS character_data) AS is_grantable FROM pg_attribute a, pg_class c, pg_namespace nc, pg_authid u_grantor, ( SELECT oid, rolname FROM pg_authid UNION ALL SELECT 0::oid, 'PUBLIC' ) AS grantee (oid, rolname), (SELECT 'SELECT' UNION ALL SELECT 'INSERT' UNION ALL SELECT 'UPDATE' UNION ALL SELECT 'REFERENCES') AS pr (type) WHERE a.attrelid = c.oid AND c.relnamespace = nc.oid AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind IN ('r', 'v') AND aclcontains(c.relacl, makeaclitem(grantee.oid, u_grantor.oid, pr.type, false)) AND (pg_has_role(u_grantor.oid, 'MEMBER') OR pg_has_role(grantee.oid, 'MEMBER') OR grantee.rolname = 'PUBLIC');GRANT SELECT ON column_privileges TO PUBLIC;/* * 20.17 * COLUMN_UDT_USAGE view */CREATE VIEW column_udt_usage AS SELECT CAST(current_database() AS sql_identifier) AS udt_catalog, CAST(coalesce(nbt.nspname, nt.nspname) AS sql_identifier) AS udt_schema, CAST(coalesce(bt.typname, t.typname) AS sql_identifier) AS udt_name, CAST(current_database() AS sql_identifier) AS table_catalog, CAST(nc.nspname AS sql_identifier) AS table_schema, CAST(c.relname AS sql_identifier) AS table_name, CAST(a.attname AS sql_identifier) AS column_name FROM pg_attribute a, pg_class c, pg_namespace nc, (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) LEFT JOIN (pg_type bt JOIN pg_namespace nbt ON (bt.typnamespace = nbt.oid)) ON (t.typtype = 'd' AND t.typbasetype = bt.oid) WHERE a.attrelid = c.oid AND a.atttypid = t.oid AND nc.oid = c.relnamespace AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v') AND pg_has_role(coalesce(bt.typowner, t.typowner), 'MEMBER');GRANT SELECT ON column_udt_usage TO PUBLIC;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?