{"Entry":{"collection":"oid","key":"regtype","name":"regtype","aliases":[],"metadata":{"aliases":[],"category":"Object name aliases","content_hash":"1a8beadc0bff5274a92f7ff99f2f795de1ed604040f1ec49e637b0af3552105c","derived_content_hash":"c2f424a0cf3fb5933e3a1e577502487f0319fce40054c61c9565b79f7a695afa","imported_at":"2026-09-30T17:44:22.579007+08:00","name":"regtype","name_zh":"regtype","repair_provenance":{"original_source_revision":"","receipt_sha256":"5a96919a75595a89dd48bde9e41397c5da245a0773c0493f56a2f41022950908","repair":"wiki-repair-20261023"},"slug":"regtype","source_rev":"wiki-repair-20261023:ada1459b5dee39c12ae5fd20784ef752ab2f65fd9d8d890965b6691d9a555d22","summary":"data type name."}},"Definition":{"Collection":"oid","Key":"regtype","SourceDatabase":"center","Version":"18","SourceTable":"oid_type","SourceKey":"regtype","SourceRevision":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","Facts":{"description":["data type name."],"description_zh":"类型regtype引用的目录pg_type含义数据类型名称示例integer","description_zh_html":"\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003cth\u003e类型\u003c/th\u003e\u003ctd\u003e\u003ccode class=\"type\"\u003eregtype\u003c/code\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003e引用的目录\u003c/th\u003e\u003ctd\u003e\u003ccode class=\"structname\"\u003epg_type\u003c/code\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003e含义\u003c/th\u003e\u003ctd\u003e数据类型名称\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003cth\u003e示例\u003c/th\u003e\u003ctd\u003e\u003ccode class=\"literal\"\u003einteger\u003c/code\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\u003cp\u003e\n    对象标识符（OID）在 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 内部被用作若干系统表的主键。类型 \u003ccode class=\"type\"\u003eoid\u003c/code\u003e 表示一个对象标识符。此外还有若干 \u003ccode class=\"type\"\u003eoid\u003c/code\u003e 的别名类型，其名称均形如\n    \u003ccode class=\"type\"\u003ereg\u003cem class=\"replaceable\"\u003e\u003ccode\u003esomething\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e。\u003ca class=\"xref\" href=\"/zh/docs/18/datatype-oid.html#DATATYPE-OID-TABLE\" title=\"表 8.26. 对象标识符类型\"\u003e表 8.26\u003c/a\u003e 给出了概要说明。\n   \u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"type\"\u003eoid\u003c/code\u003e 类型目前实现为无符号 4 字节整数。因此，在大型数据库中，它不足以提供数据库范围内的唯一性，甚至在大型的单个表中也无法保证唯一性。\n   \u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"type\"\u003eoid\u003c/code\u003e 类型本身除比较之外几乎没有其他操作。不过，它可以转换为整数，然后再用标准整数操作符进行处理。（这样做时要注意有符号与无符号可能造成的混淆。）\n   \u003c/p\u003e\u003cp\u003e\n    OID 别名类型除了专门的输入和输出例程外，没有自己的操作。这些例程能够接受并显示系统对象的符号名称，而不是 \u003ccode class=\"type\"\u003eoid\u003c/code\u003e\n    类型所使用的原始数值。别名类型简化了对象 OID 值的查找。例如，要查看与表 \u003ccode class=\"literal\"\u003emytable\u003c/code\u003e 相关的\n    \u003ccode class=\"structname\"\u003epg_attribute\u003c/code\u003e 行，可以写成：\n\u003c/p\u003e\u003cp\u003e\n    而不是：\n\u003c/p\u003e\u003cp\u003e\n    虽然这样看起来也不算太糟，但其实仍然过于简化。如果不同模式中有多个名为 \u003ccode class=\"literal\"\u003emytable\u003c/code\u003e 的表，就必须写一个复杂得多的子查询来选出正确的 OID。\u003ccode class=\"type\"\u003eregclass\u003c/code\u003e 的输入转换器会按照模式路径设置来处理表查找，因此能够自动完成\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e正确的事情\u003c/span\u003e”\u003c/span\u003e。同样，把表的 OID 转换成\n    \u003ccode class=\"type\"\u003eregclass\u003c/code\u003e，也很适合用来以符号形式显示数值 OID。\n   \u003c/p\u003e\u003cp\u003e\n    所有按命名空间分组的对象对应的 OID 别名类型，都接受模式限定名称；如果某对象在当前搜索路径下未经限定就无法找到，则其输出也会显示为模式限定名称。例如，\u003ccode class=\"literal\"\u003emyschema.mytable\u003c/code\u003e 可作为\n    \u003ccode class=\"type\"\u003eregclass\u003c/code\u003e 的输入（前提是确有此表）。该值输出时可能是\n    \u003ccode class=\"literal\"\u003emyschema.mytable\u003c/code\u003e，也可能只是\n    \u003ccode class=\"literal\"\u003emytable\u003c/code\u003e，具体取决于当前搜索路径。\u003ccode class=\"type\"\u003eregproc\u003c/code\u003e 和 \u003ccode class=\"type\"\u003eregoper\u003c/code\u003e 只接受唯一（未重载）的输入名称，因此用途有限；多数情况下，\u003ccode class=\"type\"\u003eregprocedure\u003c/code\u003e 或 \u003ccode class=\"type\"\u003eregoperator\u003c/code\u003e 更合适。对于 \u003ccode class=\"type\"\u003eregoperator\u003c/code\u003e，可以通过在未使用的操作数位置写入\n    \u003ccode class=\"literal\"\u003eNONE\u003c/code\u003e 来表示一元操作符。\n   \u003c/p\u003e\u003cp\u003e\n    这些类型的输入函数允许在各个词元之间插入空白，并且会把大写字母折叠为小写，双引号内除外；这样做是为了让语法规则更接近 SQL 中书写对象名的方式。反过来，如果需要让输出成为有效的 SQL 标识符，输出函数会自动加上双引号。例如，一个名为 \u003ccode class=\"literal\"\u003eFoo\u003c/code\u003e（大写 \u003ccode class=\"literal\"\u003eF\u003c/code\u003e）且带两个整数参数的函数，其 OID\n    可以写成 \u003ccode class=\"literal\"\u003e' \"Foo\" ( int, integer ) '::regprocedure\u003c/code\u003e。输出则会是 \u003ccode class=\"literal\"\u003e\"Foo\"(integer,integer)\u003c/code\u003e。函数名和参数类型名也都可以带模式限定。\n   \u003c/p\u003e\u003cp\u003e\n    许多内置的 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 函数接受表的 OID\n    或其他数据库对象的 OID。为了方便，这些函数会被声明为接受\n    \u003ccode class=\"type\"\u003eregclass\u003c/code\u003e（或相应的 OID 别名类型）参数。这意味着你不必手工查找对象的 OID，只需把对象名写成字符串字面值即可。例如，\u003ccode class=\"function\"\u003enextval(regclass)\u003c/code\u003e 函数接受一个序列关系的 OID，因此可以这样调用：\n\u003c/p\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"type\"\u003eregclass\u003c/code\u003e 的另一个实际用途，是查找\n    \u003ccode class=\"literal\"\u003einformation_schema\u003c/code\u003e 视图中列出的表的 OID，而这些视图本身并不直接提供此类 OID。例如，你可能想调用\n    \u003ccode class=\"function\"\u003epg_relation_size()\u003c/code\u003e 函数，而它需要表的 OID。综合上述规则，正确的写法是：\n\u003c/p\u003e\u003cp\u003e\n\u003ccode class=\"function\"\u003equote_ident()\u003c/code\u003e 函数会在需要时为标识符添加双引号。看起来似乎更简单的写法\n\u003c/p\u003e\u003cp\u003e\n\u003cspan class=\"emphasis\"\u003e\u003cem\u003e并不推荐\u003c/em\u003e\u003c/span\u003e，因为对于搜索路径之外的表，或者名字需要加引号的表，它都会失败。\n   \u003c/p\u003e\u003cp\u003e\n    大多数 OID 别名类型还有一个附加特性，就是会创建依赖关系。如果这些类型的常量出现在存储的表达式中（例如列默认表达式或视图），它就会对被引用对象建立依赖。例如，如果某列的默认表达式是\n    \u003ccode class=\"literal\"\u003enextval('my_seq'::regclass)\u003c/code\u003e，\u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 就会知道该默认表达式依赖于序列 \u003ccode class=\"literal\"\u003emy_seq\u003c/code\u003e，因此系统不允许在尚未移除该默认表达式时删除序列。改用\n    \u003ccode class=\"literal\"\u003enextval('my_seq'::text)\u003c/code\u003e 则不会建立依赖。（\u003ccode class=\"type\"\u003eregrole\u003c/code\u003e 是这一特性的例外：该类型的常量不允许出现在存储表达式中。）\n   \u003c/p\u003e","facts":[{"label":"Referenced catalog","value":"pg_type"},{"label":"Description","value":"data type name"},{"label":"Input example","value":"integer"}],"related":[{"label":"pg_type catalog","url":"/wiki/catalog/pg_type/?v=18"},{"label":"Table 8.26","url":"/docs/18/datatype-oid.html#DATATYPE-OID-TABLE"},{"label":"Table 9.76","url":"/docs/18/functions-info.html#FUNCTIONS-INFO-CATALOG-TABLE"}],"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 Documentation","revision":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38"},"sections":[{"blocks":[{"paragraphs":["Object identifiers (OIDs) are used internally by PostgreSQL as primary keys for various system tables. Type oid represents an object identifier. There are also several alias types for oid , each named reg something . Table 8.26 shows an overview.","The oid type is currently implemented as an unsigned four-byte integer. Therefore, it is not large enough to provide database-wide uniqueness in large databases, or even in large individual tables.","The oid type itself has few operations beyond comparison. It can be cast to integer, however, and then manipulated using the standard integer operators. (Beware of possible signed-versus-unsigned confusion if you do this.)"]}],"paragraphs":[],"title":"Storage and range"},{"blocks":[{"code":"SELECT * FROM pg_attribute WHERE attrelid = 'mytable'::regclass;","paragraphs":["The OID alias types have no operations of their own except for specialized input and output routines. These routines are able to accept and display symbolic names for system objects, rather than the raw numeric value that type oid would use. The alias types allow simplified lookup of OID values for objects. For example, to examine the pg_attribute rows related to a table mytable , one could write:"]},{"code":"SELECT * FROM pg_attribute\n  WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'mytable');","paragraphs":["rather than:"]},{"code":"nextval('foo')              operates on sequence foo\nnextval('FOO')              same as above\nnextval('\"Foo\"')            operates on sequence Foo\nnextval('myschema.foo')     operates on myschema.foo\nnextval('\"myschema\".foo')   same as above\nnextval('foo')              searches search path for foo","paragraphs":["While that doesn't look all that bad by itself, it's still oversimplified. A far more complicated sub-select would be needed to select the right OID if there are multiple tables named mytable in different schemas. The regclass input converter handles the table lookup according to the schema path setting, and so it does the “right thing” automatically. Similarly, casting a table's OID to regclass is handy for symbolic display of a numeric OID.","All of the OID alias types for objects that are grouped by namespace accept schema-qualified names, and will display schema-qualified names on output if the object would not be found in the current search path without being qualified. For example, myschema.mytable is acceptable input for regclass (if there is such a table). That value might be output as myschema.mytable , or just mytable , depending on the current search path. The regproc and regoper alias types will only accept input names that are unique (not overloaded), so they are of limited use; for most uses regprocedure or regoperator are more appropriate. For regoperator , unary operators are identified by writing NONE for the unused operand.","The input functions for these types allow whitespace between tokens, and will fold upper-case letters to lower case, except within double quotes; this is done to make the syntax rules similar to the way object names are written in SQL. Conversely, the output functions will use double quotes if needed to make the output be a valid SQL identifier. For example, the OID of a function named Foo (with upper case F ) taking two integer arguments could be entered as ' \"Foo\" ( int, integer ) '::regprocedure . The output would look like \"Foo\"(integer,integer) . Both the function name and the argument type names could be schema-qualified, too.","Many built-in PostgreSQL functions accept the OID of a table, or another kind of database object, and for convenience are declared as taking regclass (or the appropriate OID alias type). This means you do not have to look up the object's OID by hand, but can just enter its name as a string literal. For example, the nextval(regclass) function takes a sequence relation's OID, so you could call it like this:"]}],"paragraphs":[],"title":"Name resolution and search path"},{"blocks":[{"code":"nextval('foo'::text)      foo is looked up at runtime","paragraphs":["When you write the argument of such a function as an unadorned literal string, it becomes a constant of type regclass (or the appropriate type). Since this is really just an OID, it will track the originally identified object despite later renaming, schema reassignment, etc. This “early binding” behavior is usually desirable for object references in column defaults and views. But sometimes you might want “late binding” where the object reference is resolved at run time. To get late-binding behavior, force the constant to be stored as a text constant instead of regclass :"]},{"paragraphs":["The to_regclass() function and its siblings can also be used to perform run-time lookups. See Table 9.76 ."]}],"paragraphs":[],"title":"Early and late binding"},{"blocks":[{"code":"SELECT table_schema, table_name,\n       pg_relation_size((quote_ident(table_schema) || '.' ||\n                         quote_ident(table_name))::regclass)\nFROM information_schema.tables\nWHERE ...","paragraphs":["Another practical example of use of regclass is to look up the OID of a table listed in the information_schema views, which don't supply such OIDs directly. One might for example wish to call the pg_relation_size() function, which requires the table OID. Taking the above rules into account, the correct way to do that is"]},{"code":"SELECT pg_relation_size(table_name)\nFROM information_schema.tables\nWHERE ...","paragraphs":["The quote_ident() function will take care of double-quoting the identifiers where needed. The seemingly easier"]},{"paragraphs":["is not recommended , because it will fail for tables that are outside your search path or have names that require quoting."]}],"paragraphs":[],"title":"Looking up OIDs through the information schema"},{"blocks":[{"paragraphs":["An additional property of most of the OID alias types is the creation of dependencies. If a constant of one of these types appears in a stored expression (such as a column default expression or view), it creates a dependency on the referenced object. For example, if a column has a default expression nextval('my_seq'::regclass) , PostgreSQL understands that the default expression depends on the sequence my_seq , so the system will not let the sequence be dropped without first removing the default expression. The alternative of nextval('my_seq'::text) does not create a dependency. ( regrole is an exception to this property. Constants of this type are not allowed in stored expressions.)"]}],"paragraphs":[],"title":"dependencies"}],"sources":[{"label":"PostgreSQL 18.6 Documentation","sha256":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","url":"/docs/18/datatype-oid.html#DATATYPE-OID-TABLE"},{"label":"PostgreSQL 18 online manual","url":"https://www.postgresql.org/docs/18/datatype-oid.html#DATATYPE-OID-TABLE"}],"translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/datatype-oid.html","sha256":"f7769489aed6ea9bae7befeda7d9264ccc2752ef906f9137b4d08dd3569bba21"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-pgdoc"},"ManualEvidence":{"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 Documentation","revision":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38"},"sources":[{"label":"PostgreSQL 18.6 Documentation","sha256":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","url":"/docs/18/datatype-oid.html#DATATYPE-OID-TABLE"},{"label":"PostgreSQL 18 online manual","url":"https://www.postgresql.org/docs/18/datatype-oid.html#DATATYPE-OID-TABLE"}]},"MeasuredEvidence":{}},"Text":{"Collection":"oid","Key":"regtype","SourceDatabase":"center","Version":"18","Locale":"en","Title":"regtype","Summary":"data type name.","BodyHTML":"\u003cp\u003edata type name.\u003c/p\u003e","SourceRevision":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","ContentHash":"89273c79df0bd48a66058a84c3e9fa4dc16ef48f53d8d16351e46c12e17c27b2","Payload":{"description":["data type name."],"related":[{"label":"pg_type catalog","url":"/wiki/catalog/pg_type/?v=18"},{"label":"Table 8.26","url":"/docs/18/datatype-oid.html#DATATYPE-OID-TABLE"},{"label":"Table 9.76","url":"/docs/18/functions-info.html#FUNCTIONS-INFO-CATALOG-TABLE"}],"sections":[{"blocks":[{"paragraphs":["Object identifiers (OIDs) are used internally by PostgreSQL as primary keys for various system tables. Type oid represents an object identifier. There are also several alias types for oid , each named reg something . Table 8.26 shows an overview.","The oid type is currently implemented as an unsigned four-byte integer. Therefore, it is not large enough to provide database-wide uniqueness in large databases, or even in large individual tables.","The oid type itself has few operations beyond comparison. It can be cast to integer, however, and then manipulated using the standard integer operators. (Beware of possible signed-versus-unsigned confusion if you do this.)"]}],"paragraphs":[],"title":"Storage and range"},{"blocks":[{"code":"SELECT * FROM pg_attribute WHERE attrelid = 'mytable'::regclass;","paragraphs":["The OID alias types have no operations of their own except for specialized input and output routines. These routines are able to accept and display symbolic names for system objects, rather than the raw numeric value that type oid would use. The alias types allow simplified lookup of OID values for objects. For example, to examine the pg_attribute rows related to a table mytable , one could write:"]},{"code":"SELECT * FROM pg_attribute\n  WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'mytable');","paragraphs":["rather than:"]},{"code":"nextval('foo')              operates on sequence foo\nnextval('FOO')              same as above\nnextval('\"Foo\"')            operates on sequence Foo\nnextval('myschema.foo')     operates on myschema.foo\nnextval('\"myschema\".foo')   same as above\nnextval('foo')              searches search path for foo","paragraphs":["While that doesn't look all that bad by itself, it's still oversimplified. A far more complicated sub-select would be needed to select the right OID if there are multiple tables named mytable in different schemas. The regclass input converter handles the table lookup according to the schema path setting, and so it does the “right thing” automatically. Similarly, casting a table's OID to regclass is handy for symbolic display of a numeric OID.","All of the OID alias types for objects that are grouped by namespace accept schema-qualified names, and will display schema-qualified names on output if the object would not be found in the current search path without being qualified. For example, myschema.mytable is acceptable input for regclass (if there is such a table). That value might be output as myschema.mytable , or just mytable , depending on the current search path. The regproc and regoper alias types will only accept input names that are unique (not overloaded), so they are of limited use; for most uses regprocedure or regoperator are more appropriate. For regoperator , unary operators are identified by writing NONE for the unused operand.","The input functions for these types allow whitespace between tokens, and will fold upper-case letters to lower case, except within double quotes; this is done to make the syntax rules similar to the way object names are written in SQL. Conversely, the output functions will use double quotes if needed to make the output be a valid SQL identifier. For example, the OID of a function named Foo (with upper case F ) taking two integer arguments could be entered as ' \"Foo\" ( int, integer ) '::regprocedure . The output would look like \"Foo\"(integer,integer) . Both the function name and the argument type names could be schema-qualified, too.","Many built-in PostgreSQL functions accept the OID of a table, or another kind of database object, and for convenience are declared as taking regclass (or the appropriate OID alias type). This means you do not have to look up the object's OID by hand, but can just enter its name as a string literal. For example, the nextval(regclass) function takes a sequence relation's OID, so you could call it like this:"]}],"paragraphs":[],"title":"Name resolution and search path"},{"blocks":[{"code":"nextval('foo'::text)      foo is looked up at runtime","paragraphs":["When you write the argument of such a function as an unadorned literal string, it becomes a constant of type regclass (or the appropriate type). Since this is really just an OID, it will track the originally identified object despite later renaming, schema reassignment, etc. This “early binding” behavior is usually desirable for object references in column defaults and views. But sometimes you might want “late binding” where the object reference is resolved at run time. To get late-binding behavior, force the constant to be stored as a text constant instead of regclass :"]},{"paragraphs":["The to_regclass() function and its siblings can also be used to perform run-time lookups. See Table 9.76 ."]}],"paragraphs":[],"title":"Early and late binding"},{"blocks":[{"code":"SELECT table_schema, table_name,\n       pg_relation_size((quote_ident(table_schema) || '.' ||\n                         quote_ident(table_name))::regclass)\nFROM information_schema.tables\nWHERE ...","paragraphs":["Another practical example of use of regclass is to look up the OID of a table listed in the information_schema views, which don't supply such OIDs directly. One might for example wish to call the pg_relation_size() function, which requires the table OID. Taking the above rules into account, the correct way to do that is"]},{"code":"SELECT pg_relation_size(table_name)\nFROM information_schema.tables\nWHERE ...","paragraphs":["The quote_ident() function will take care of double-quoting the identifiers where needed. The seemingly easier"]},{"paragraphs":["is not recommended , because it will fail for tables that are outside your search path or have names that require quoting."]}],"paragraphs":[],"title":"Looking up OIDs through the information schema"},{"blocks":[{"paragraphs":["An additional property of most of the OID alias types is the creation of dependencies. If a constant of one of these types appears in a stored expression (such as a column default expression or view), it creates a dependency on the referenced object. For example, if a column has a default expression nextval('my_seq'::regclass) , PostgreSQL understands that the default expression depends on the sequence my_seq , so the system will not let the sequence be dropped without first removing the default expression. The alternative of nextval('my_seq'::text) does not create a dependency. ( regrole is an exception to this property. Constants of this type are not allowed in stored expressions.)"]}],"paragraphs":[],"title":"dependencies"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
