在Postgres 9.1中确定表的OID? [英] Determining the OID of a table in Postgres 9.1?

查看:131
本文介绍了在Postgres 9.1中确定表的OID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何在Postgres 9.1中查找表的OID吗?我正在编写一个更新脚本,该脚本在尝试创建列之前需要测试表中是否存在该列。这是为了防止第一个脚本运行后出错。

Does anyone know how to find the OID of a table in Postgres 9.1? I am writing an update script that needs to test for the existence of a column in a table before it tries to create the column. This is to prevent run of the script after the first from erroring out.

推荐答案

postgres目录表 pg_class 是您应该查看的内容。每个表应该有一行,表名在 relname 列中,而oid在隐藏列 oid 。

The postgres catalog table pg_class is what you should look at. There should be one row per table, with the table name in the column relname, and the oid in the hidden column oid.

目录表位于 postgres 数据库中,因此请确保连接至该数据库,而不是应用程序数据库。

The catalog tables are in the postgres database, so make sure to connect to that, rather than your application database.

您可能还对 pg_attribute 目录表感兴趣,该表每表列包含一行。

You may also be interested in the pg_attribute catalog table, which includes one row per table column.

请参阅: http:/ /www.postgresql.org/docs/current/static/catalog-pg-class.html http://www.postgresql.org/docs/current/static/catalog-pg-attribute.html

这篇关于在Postgres 9.1中确定表的OID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆