pg数据库如何查询图形库全库字段与注释并修改字段注释,可对应arcgis字段别名
时间: 2024-01-10 15:02:34 浏览: 91
你可以使用以下的 SQL 语句来查询 pg 数据库中全库的图形库字段名、注释和对应的 ArcGIS 字段别名:
```
SELECT
n.nspname AS schema_name,
c.relname AS table_name,
a.attname AS column_name,
pg_catalog.col_description(a.attrelid, a.attnum) AS column_comment,
pg_catalog.obj_description(c.oid) AS table_comment,
pg_catalog.pg_get_expr(ad.adbin, ad.adrelid) AS column_default,
pg_catalog.format_type(a.atttypid, a.atttypmod) AS column_data_type,
pg_catalog.pg_get_userbyid(c.relowner) AS table_owner,
a.attnotnull AS column_not_null,
d.adsrc AS column_check_constraint,
a.attnum AS column_position,
pg_catalog.col_aliases(a.attrelid, a.attnum) AS column_alias
FROM
pg_catalog.pg_attribute a
INNER JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
INNER JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_catalog.pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum
LEFT JOIN pg_catalog.pg_constraint con ON con.conrelid = c.oid AND a.attnum = ANY (con.conkey)
LEFT JOIN pg_catalog.pg_attrdef d ON d.adrelid = con.confrelid AND d.adnum = con.confkey
WHERE
a.attnum > 0 AND
NOT a.attisdropped AND
c.relkind = 'r' AND
n.nspname = 'public'
ORDER BY
c.relname ASC,
a.attnum ASC;
```
这个 SQL 语句会返回一个结果集,其中包含了每个表的每个字段及其对应的注释、默认值、数据类型、是否非空、检查约束、位置和 ArcGIS 字段别名。
如果你想修改某个字段的注释、默认值、检查约束等信息,可以使用以下的 SQL 语句:
```
-- 修改字段注释
COMMENT ON COLUMN table_name.column_name IS 'new_comment';
-- 修改字段默认值
ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT 'new_default';
-- 修改字段检查约束
ALTER TABLE table_name ADD CONSTRAINT check_constraint_name CHECK (column_name > 0);
```
如果你想修改某个字段的 ArcGIS 字段别名,可以在 ArcGIS 中打开图层属性面板,切换到“字段”选项卡,修改相应字段的别名即可。注意,修改后的别名只在 ArcGIS 中生效,不会修改数据库中的字段名。
阅读全文