{"Entry":{"collection":"type","key":"domains","name":"Domains","aliases":[],"metadata":{"aliases":[],"category":"Type families","content_hash":"d34b22e8ce19ae8f43c2a4fccd4bd2515a0a3094e4ec3b90ae9477547e5309f6","derived_content_hash":"3b6c412b16bce8681810687452f4a5ad572186cd05a853982dd6acea607bdb0d","imported_at":"2026-09-30T00:40:35.700533+08:00","name":"Domains","name_zh":"","slug":"domains","summary":"CREATE DOMAIN — define a new domain"}},"Definition":{"Collection":"type","Key":"domains","SourceDatabase":"center","Version":"18","SourceTable":"data_type","SourceKey":"domains","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"aliases":[],"casts":[],"catalog":{},"coverage":"documented type family or SQL syntax; not a catalog object","description":["A domain is a user-defined data type that is based on another underlying type . Optionally, it can have constraints that restrict its valid values to a subset of what the underlying type would allow. Otherwise it behaves like the underlying type — for example, any operator or function that can be applied to the underlying type will work on the domain type. The underlying type can be any built-in or user-defined base type, enum type, array type, composite type, range type, or another domain."],"description_zh":"域 是一种用户定义的数据类型，它基于另一种 底层类型 。根据需要，它可以有约束来限制其有效值为底层类型所允许值的一个子集。除此之外，它的行为与底层类型相同 — 例如，任何适用于底层类型的操作符或函数都对该域类型有效。底层类型可以是任何内置或者用户定义的基础类型、枚举类型、数组类型、复合类型、范围类型或者另一个域。","description_zh_html":"\u003cp\u003e域 是一种用户定义的数据类型，它基于另一种 底层类型 。根据需要，它可以有约束来限制其有效值为底层类型所允许值的一个子集。除此之外，它的行为与底层类型相同 — 例如，任何适用于底层类型的操作符或函数都对该域类型有效。底层类型可以是任何内置或者用户定义的基础类型、枚举类型、数组类型、复合类型、范围类型或者另一个域。\u003c/p\u003e\u003ch3\u003e同版本中文手册节选\u003c/h3\u003e\u003cp\u003e\n\u003cem class=\"firstterm\"\u003e域\u003c/em\u003e是一种用户定义的数据类型，它基于另一种\u003cem class=\"firstterm\"\u003e底层类型\u003c/em\u003e。根据需要，它可以有约束来限制其有效值为底层类型所允许值的一个子集。除此之外，它的行为与底层类型相同 — 例如，任何适用于底层类型的操作符或函数都对该域类型有效。底层类型可以是任何内置或者用户定义的基础类型、枚举类型、数组类型、复合类型、范围类型或者另一个域。\n   \u003c/p\u003e\u003cp\u003e\n    例如，我们可以基于整数创建一个只接受正整数的域：\n\u003c/p\u003e\u003cp\u003e\n    当底层类型的一个操作符或函数被应用于一个域值时，域会被自动向下转换为底层类型。因此，\u003ccode class=\"literal\"\u003emytable.id - 1\u003c/code\u003e 的结果会被认为是类型 \u003ccode class=\"type\"\u003einteger\u003c/code\u003e 而不是 \u003ccode class=\"type\"\u003eposint\u003c/code\u003e。我们可以写成\u003ccode class=\"literal\"\u003e(mytable.id - 1)::posint\u003c/code\u003e 来把结果转换回 \u003ccode class=\"type\"\u003eposint\u003c/code\u003e，这会导致域的约束被重新检查。在这种情况下，如果该表达式被应用于一个值为 1 的 \u003ccode class=\"structfield\"\u003eid\u003c/code\u003e 就会报错。把底层类型的值赋给域类型的一个字段或者变量不需要写显式的类型转换，但是域的约束将会被检查。\n   \u003c/p\u003e\u003cp\u003e\n    更多信息请参考 \u003ca class=\"xref\" href=\"/zh/docs/18/sql-createdomain.html\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE DOMAIN\u003c/span\u003e\u003c/a\u003e。\n   \u003c/p\u003e\u003cp\u003e\u003ca href=\"/zh/docs/18/domains.html\"\u003e查看完整中文手册与上下文\u003c/a\u003e。\u003c/p\u003e","facts":[{"label":"Object boundary","value":"User-defined type family; not a finite list of user objects"}],"facts_zh":[{"label":"对象边界","value":"用户定义类型族；不代表用户对象的有限清单"}],"manual_html":"\u003cdiv class=\"sect1\" id=\"DOMAINS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e8.18. Domain Types \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eA \u003cem class=\"firstterm\"\u003edomain\u003c/em\u003e is a user-defined data type that is based on another \u003cem class=\"firstterm\"\u003eunderlying type\u003c/em\u003e. Optionally, it can have constraints that restrict its valid values to a subset of what the underlying type would allow. Otherwise it behaves like the underlying type — for example, any operator or function that can be applied to the underlying type will work on the domain type. The underlying type can be any built-in or user-defined base type, enum type, array type, composite type, range type, or another domain.\u003c/p\u003e\n\u003cp\u003eFor example, we could create a domain over integers that accepts only positive integers:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE DOMAIN posint AS integer CHECK (VALUE \u0026gt; 0);\nCREATE TABLE mytable (id posint);\nINSERT INTO mytable VALUES(1);   -- works\nINSERT INTO mytable VALUES(-1);  -- fails\n\u003c/pre\u003e\n\u003cp\u003eWhen an operator or function of the underlying type is applied to a domain value, the domain is automatically down-cast to the underlying type. Thus, for example, the result of \u003ccode class=\"literal\"\u003emytable.id - 1\u003c/code\u003e is considered to be of type \u003ccode class=\"type\"\u003einteger\u003c/code\u003e not \u003ccode class=\"type\"\u003eposint\u003c/code\u003e. We could write \u003ccode class=\"literal\"\u003e(mytable.id - 1)::posint\u003c/code\u003e to cast the result back to \u003ccode class=\"type\"\u003eposint\u003c/code\u003e, causing the domain's constraints to be rechecked. In this case, that would result in an error if the expression had been applied to an \u003ccode class=\"structfield\"\u003eid\u003c/code\u003e value of 1. Assigning a value of the underlying type to a field or variable of the domain type is allowed without writing an explicit cast, but the domain's constraints will be checked.\u003c/p\u003e\n\u003cp\u003eFor additional information see \u003ca class=\"xref\" href=\"/docs/18/sql-createdomain.html\" title=\"CREATE DOMAIN\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE DOMAIN\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/div\u003e","manual_path":"domains.html","operator_classes":[],"operators":[],"ranges":[],"related":[],"release":{"channel":"stable","label":"18.6","major":"18","manual_sha256":{"arrays.html":"0e1d5c5a7b4a949d4439995f44f74ad4264e050d16eb9ad2a850fbaee04032df","catalog-pg-type.html":"ea9c9313bab8e92a7da18ebc50c7ff1f908dd80999a7e0ca3bbc82ba626c58d4","datatype-binary.html":"0c03ec47b76e37888a3da7f5dcfd340128a5d356642a85185cc9ebe17856a904","datatype-bit.html":"c49124aad561636c18080b9e09572fde7785a6b9eae86f5a33283f0fd6774c37","datatype-boolean.html":"b633f663e6c8276e7056287640c413aa79dbc15d5353cee0d41653d58d376956","datatype-character.html":"c73eebe413ea709a7792e4cfc3cfe9fb68cb496ebe83c3ebaa9d09f8c40d0f73","datatype-datetime.html":"e366275d8b13845bfa4ef0d68faa093e5f3ecb708a1ec870cbcbf7e425b85699","datatype-enum.html":"cab38e53222e30cc94b24de4b33634fd22d7c93f58ebcf35f646c9b8da78fae8","datatype-geometric.html":"0eb3053cfe7d6b0a4b5592c5d7af8d97cae527e87f063c5793413bcba5c14cd9","datatype-json.html":"650162a05b660146b500a205d523374d00aee117a6a6240d30262be51b6e33e5","datatype-money.html":"8b29c14b90679683ac5c472b59a0a7e2853f32cc7db43fab417b2697a6879964","datatype-net-types.html":"96846e641cc37727ddcd8b8a1aa0dbe33cd9787760a2b4efb0dcb9403d5be63f","datatype-numeric.html":"b74619f7ac2f1ca9f85c48073df78c33dd30e464e61baba6008634534edcb500","datatype-oid.html":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","datatype-pg-lsn.html":"339172f5107cc7eb7139bec911277647219e92a532cebd0f3da0a5dacf8195af","datatype-pseudo.html":"c7cf0b8214304bd8702c95f2142671ae5f0d631f83717f9c07d9e1f2579961b4","datatype-textsearch.html":"4b15e05be8b49a71b28aea22f2c46d0dbf639a91e7b4fe129a4c737c6daad47c","datatype-uuid.html":"292b307b3223c6182bdba687e7f69e6dca9038430143ad79d56327f6ed4c3246","datatype-xml.html":"061fc2295b7b69be704f0a741b8decd10ad721059f871fb0243c669bb54d7822","datatype.html":"e581f67c74e42006289638c8659e9b338adbfd7f068bd8bf2b3be3880fcd2254","domains.html":"82d486973ccc35d14276627a67ac76b434452f23f9ed4d8aa3fbb01fdf285fc2","functions-info.html":"78ac80bf81da2e4f4a33f3b850faa86f0f58ec54a083d6c31da557907de0df87","rangetypes.html":"e4960abc7ce8e51d794f94f1e57b099d30b7f75dd7f2b23a960eef91f6291c33","rowtypes.html":"74f99e029c3a9edfd3e18810ba3c8cb66d3aada91eb67b86476560871e6617e9","sql-createdomain.html":"e94f927196de1b0ea1ce35cd4603c1f6f544439adcc0edf1c4222358e832245b"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_files":{"doc/src/sgml/datatype.sgml":"86328daa77e20d81d222376ec0306d9841a17104e436c08d138eb763aefb3700","src/include/catalog/pg_am.dat":"b3cb86b102a42fb0024cbd99779c9897afb40d12a71f5cc5a0e5aee7ff2f9969","src/include/catalog/pg_am.h":"3426799df799f32163fcc0765f43dbdb5e88e626acf31284fef9fc6014b69d8e","src/include/catalog/pg_cast.dat":"97911281ca2c81917394ccb2ec13367e37c6801fd461d5e1a3d2f28b911b46b2","src/include/catalog/pg_cast.h":"de585c7df687d698e7d1d100dce8a794ac9da52414ea48169191019178c8f053","src/include/catalog/pg_opclass.dat":"4ee7d3619a6aa106e1c0db55de903931c7d11b1c60ba053a022519c55f8ee668","src/include/catalog/pg_opclass.h":"9c218537806c8ef0398302faaca7f91315dfc1198c48706cebffb479b68defaf","src/include/catalog/pg_operator.dat":"5d35b9b2ef5f9797cc815263927ef8a12367fedace53e828b4e8b320e2a7f703","src/include/catalog/pg_operator.h":"621b18cfffe102413d79b746ce7a10f77fc60fdd097bac34c22b31070d3ee3c4","src/include/catalog/pg_opfamily.dat":"3b694879027b858f2ecf1fa1152b7e30c6e15a216ba99c2384291c30e9d52311","src/include/catalog/pg_opfamily.h":"e1f5fc8aebd3042df847455bf66bf755f768c2aa8a9b03d22f7ec8563eba59c0","src/include/catalog/pg_proc.dat":"1f934ce80d460159dda137714374a35f9896315ea2476709cbb4da13b38ef95a","src/include/catalog/pg_proc.h":"f7d59f07c5b95e2f3c7141762a0f576e8a3af7581ba54c27537f4d500472bea5","src/include/catalog/pg_range.dat":"5c2271f8e89e9378d1887204e5785060b77405b5f0ff3e6c719250c9c1dcfcc4","src/include/catalog/pg_range.h":"45546d952b5181f989bd9234721897fc2b37005c8e49ce2ddc156f26974c3ca4","src/include/catalog/pg_type.dat":"5f5887b75677cba2d4a1a0cfeb355df5ed91f85d385fac88bd8d7c605b3578f9","src/include/catalog/pg_type.h":"8fb198749fd82b6c1818a3c18455f226f66116fcfeb3d4959c65ce3fda22802e"},"source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"sections_zh":[],"signature":"Domains","sources":[{"label":"PostgreSQL 18 English manual","path":"domains.html","sha256":"82d486973ccc35d14276627a67ac76b434452f23f9ed4d8aa3fbb01fdf285fc2","url":"/docs/18/domains.html"}],"tables_zh":[],"zh_from":{"authored_translation":"preserved-translation-of-reverified-type-description","body_sha256":"8c91f448f8e066bd264450907899f52ef09569c775ce660246c07095682b7350","kind":"same-version-chinese-manual-with-preserved-translation-of-reverified-type-description","manual":{"anchor":"","build_id":107,"extraction":"concept-introduction","fragment_sha256":"68997490f0d747e294d4ab9ef0d3385f5e315f3fb2d7a5965acdc6a07606be0c","locale":"zh-Hans","page_key":"domains.html","source_hash":"beb3c74521a11c22fad1b85dc7c09f3624a8f16e79c465cd9a3263846bcc1d66","source_revision":"unknown:rendered-translation-baseline","translated_from_revision":null,"translation_revision":"git:b1b500221dbe5437cfca004d6b04d3f6e422765d;html-sha256:08e987a66af27b98444a8057c256314eafa13611a3fb9e888214fc436824244b","url":"/zh/docs/18/domains.html","version":"18"},"runtime_rerun":false,"source_facts_revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","summary_translation":{"english_description_sha256":"03f426f8cb81a01c095541aa2c97d30491120128cac961694e74d8c27e708be9","key":"domains","kind":"preserved-translation-of-reverified-type-description","localized_description_sha256":"7d6245af7d61a063366c20cd2b22c73a2c609dc976bc8a26518984281245062d","original_localization_sources":[{"language":"zh","matched_nodes":["#DOMAINS/div[0]","#DOMAINS/p[3]","#DOMAINS/p[4]","#DOMAINS/p[6]","#DOMAINS/p[7]"],"method":"same-major semantic node","sha256":"412876c135b4263e0061360770c16d483fa7f96bd0a3fd595ee1c8bb27e5228b","url":"/docs/18/domains.html"}],"source_database":"pgweb","table":"data_type","version":"18"}}},"ManualEvidence":{"manual_path":"domains.html","release":{"channel":"stable","label":"18.6","major":"18","manual_sha256":{"arrays.html":"0e1d5c5a7b4a949d4439995f44f74ad4264e050d16eb9ad2a850fbaee04032df","catalog-pg-type.html":"ea9c9313bab8e92a7da18ebc50c7ff1f908dd80999a7e0ca3bbc82ba626c58d4","datatype-binary.html":"0c03ec47b76e37888a3da7f5dcfd340128a5d356642a85185cc9ebe17856a904","datatype-bit.html":"c49124aad561636c18080b9e09572fde7785a6b9eae86f5a33283f0fd6774c37","datatype-boolean.html":"b633f663e6c8276e7056287640c413aa79dbc15d5353cee0d41653d58d376956","datatype-character.html":"c73eebe413ea709a7792e4cfc3cfe9fb68cb496ebe83c3ebaa9d09f8c40d0f73","datatype-datetime.html":"e366275d8b13845bfa4ef0d68faa093e5f3ecb708a1ec870cbcbf7e425b85699","datatype-enum.html":"cab38e53222e30cc94b24de4b33634fd22d7c93f58ebcf35f646c9b8da78fae8","datatype-geometric.html":"0eb3053cfe7d6b0a4b5592c5d7af8d97cae527e87f063c5793413bcba5c14cd9","datatype-json.html":"650162a05b660146b500a205d523374d00aee117a6a6240d30262be51b6e33e5","datatype-money.html":"8b29c14b90679683ac5c472b59a0a7e2853f32cc7db43fab417b2697a6879964","datatype-net-types.html":"96846e641cc37727ddcd8b8a1aa0dbe33cd9787760a2b4efb0dcb9403d5be63f","datatype-numeric.html":"b74619f7ac2f1ca9f85c48073df78c33dd30e464e61baba6008634534edcb500","datatype-oid.html":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","datatype-pg-lsn.html":"339172f5107cc7eb7139bec911277647219e92a532cebd0f3da0a5dacf8195af","datatype-pseudo.html":"c7cf0b8214304bd8702c95f2142671ae5f0d631f83717f9c07d9e1f2579961b4","datatype-textsearch.html":"4b15e05be8b49a71b28aea22f2c46d0dbf639a91e7b4fe129a4c737c6daad47c","datatype-uuid.html":"292b307b3223c6182bdba687e7f69e6dca9038430143ad79d56327f6ed4c3246","datatype-xml.html":"061fc2295b7b69be704f0a741b8decd10ad721059f871fb0243c669bb54d7822","datatype.html":"e581f67c74e42006289638c8659e9b338adbfd7f068bd8bf2b3be3880fcd2254","domains.html":"82d486973ccc35d14276627a67ac76b434452f23f9ed4d8aa3fbb01fdf285fc2","functions-info.html":"78ac80bf81da2e4f4a33f3b850faa86f0f58ec54a083d6c31da557907de0df87","rangetypes.html":"e4960abc7ce8e51d794f94f1e57b099d30b7f75dd7f2b23a960eef91f6291c33","rowtypes.html":"74f99e029c3a9edfd3e18810ba3c8cb66d3aada91eb67b86476560871e6617e9","sql-createdomain.html":"e94f927196de1b0ea1ce35cd4603c1f6f544439adcc0edf1c4222358e832245b"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_files":{"doc/src/sgml/datatype.sgml":"86328daa77e20d81d222376ec0306d9841a17104e436c08d138eb763aefb3700","src/include/catalog/pg_am.dat":"b3cb86b102a42fb0024cbd99779c9897afb40d12a71f5cc5a0e5aee7ff2f9969","src/include/catalog/pg_am.h":"3426799df799f32163fcc0765f43dbdb5e88e626acf31284fef9fc6014b69d8e","src/include/catalog/pg_cast.dat":"97911281ca2c81917394ccb2ec13367e37c6801fd461d5e1a3d2f28b911b46b2","src/include/catalog/pg_cast.h":"de585c7df687d698e7d1d100dce8a794ac9da52414ea48169191019178c8f053","src/include/catalog/pg_opclass.dat":"4ee7d3619a6aa106e1c0db55de903931c7d11b1c60ba053a022519c55f8ee668","src/include/catalog/pg_opclass.h":"9c218537806c8ef0398302faaca7f91315dfc1198c48706cebffb479b68defaf","src/include/catalog/pg_operator.dat":"5d35b9b2ef5f9797cc815263927ef8a12367fedace53e828b4e8b320e2a7f703","src/include/catalog/pg_operator.h":"621b18cfffe102413d79b746ce7a10f77fc60fdd097bac34c22b31070d3ee3c4","src/include/catalog/pg_opfamily.dat":"3b694879027b858f2ecf1fa1152b7e30c6e15a216ba99c2384291c30e9d52311","src/include/catalog/pg_opfamily.h":"e1f5fc8aebd3042df847455bf66bf755f768c2aa8a9b03d22f7ec8563eba59c0","src/include/catalog/pg_proc.dat":"1f934ce80d460159dda137714374a35f9896315ea2476709cbb4da13b38ef95a","src/include/catalog/pg_proc.h":"f7d59f07c5b95e2f3c7141762a0f576e8a3af7581ba54c27537f4d500472bea5","src/include/catalog/pg_range.dat":"5c2271f8e89e9378d1887204e5785060b77405b5f0ff3e6c719250c9c1dcfcc4","src/include/catalog/pg_range.h":"45546d952b5181f989bd9234721897fc2b37005c8e49ce2ddc156f26974c3ca4","src/include/catalog/pg_type.dat":"5f5887b75677cba2d4a1a0cfeb355df5ed91f85d385fac88bd8d7c605b3578f9","src/include/catalog/pg_type.h":"8fb198749fd82b6c1818a3c18455f226f66116fcfeb3d4959c65ce3fda22802e"},"source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"label":"PostgreSQL 18 English manual","path":"domains.html","sha256":"82d486973ccc35d14276627a67ac76b434452f23f9ed4d8aa3fbb01fdf285fc2","url":"/docs/18/domains.html"}]},"MeasuredEvidence":{}},"Text":{"Collection":"type","Key":"domains","SourceDatabase":"center","Version":"18","Locale":"en","Title":"Domains","Summary":"A domain is a user-defined data type that is based on another underlying type . Optionally, it can have constraints that restrict its valid values to a subset of what the underlying type would allow. Otherwise it behaves like the underlying type — for example, any operator or function that can be applied to the underlying type will work on the domain type. The underlying type can be any built-in or user-defined base type, enum type, array type, composite type, range type, or another domain.","BodyHTML":"\u003cdiv id=\"DOMAINS\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2\u003e8.18. Domain Types \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eA \u003cem\u003edomain\u003c/em\u003e is a user-defined data type that is based on another \u003cem\u003eunderlying type\u003c/em\u003e. Optionally, it can have constraints that restrict its valid values to a subset of what the underlying type would allow. Otherwise it behaves like the underlying type — for example, any operator or function that can be applied to the underlying type will work on the domain type. The underlying type can be any built-in or user-defined base type, enum type, array type, composite type, range type, or another domain.\u003c/p\u003e\n\u003cp\u003eFor example, we could create a domain over integers that accepts only positive integers:\u003c/p\u003e\n\u003cpre\u003eCREATE DOMAIN posint AS integer CHECK (VALUE \u0026gt; 0);\nCREATE TABLE mytable (id posint);\nINSERT INTO mytable VALUES(1);   -- works\nINSERT INTO mytable VALUES(-1);  -- fails\n\u003c/pre\u003e\n\u003cp\u003eWhen an operator or function of the underlying type is applied to a domain value, the domain is automatically down-cast to the underlying type. Thus, for example, the result of \u003ccode\u003emytable.id - 1\u003c/code\u003e is considered to be of type \u003ccode\u003einteger\u003c/code\u003e not \u003ccode\u003eposint\u003c/code\u003e. We could write \u003ccode\u003e(mytable.id - 1)::posint\u003c/code\u003e to cast the result back to \u003ccode\u003eposint\u003c/code\u003e, causing the domain\u0026#39;s constraints to be rechecked. In this case, that would result in an error if the expression had been applied to an \u003ccode\u003eid\u003c/code\u003e value of 1. Assigning a value of the underlying type to a field or variable of the domain type is allowed without writing an explicit cast, but the domain\u0026#39;s constraints will be checked.\u003c/p\u003e\n\u003cp\u003eFor additional information see \u003ca href=\"/docs/18/sql-createdomain.html\" title=\"CREATE DOMAIN\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE DOMAIN\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/div\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"f04592c5ceb7b1d43c0d064335f4f4ac6e80745d6a5a72080f2046d12cd83632","Payload":{"description":["A domain is a user-defined data type that is based on another underlying type . Optionally, it can have constraints that restrict its valid values to a subset of what the underlying type would allow. Otherwise it behaves like the underlying type — for example, any operator or function that can be applied to the underlying type will work on the domain type. The underlying type can be any built-in or user-defined base type, enum type, array type, composite type, range type, or another domain."],"manual_html":"\u003cdiv class=\"sect1\" id=\"DOMAINS\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e8.18. Domain Types \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eA \u003cem class=\"firstterm\"\u003edomain\u003c/em\u003e is a user-defined data type that is based on another \u003cem class=\"firstterm\"\u003eunderlying type\u003c/em\u003e. Optionally, it can have constraints that restrict its valid values to a subset of what the underlying type would allow. Otherwise it behaves like the underlying type — for example, any operator or function that can be applied to the underlying type will work on the domain type. The underlying type can be any built-in or user-defined base type, enum type, array type, composite type, range type, or another domain.\u003c/p\u003e\n\u003cp\u003eFor example, we could create a domain over integers that accepts only positive integers:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eCREATE DOMAIN posint AS integer CHECK (VALUE \u0026gt; 0);\nCREATE TABLE mytable (id posint);\nINSERT INTO mytable VALUES(1);   -- works\nINSERT INTO mytable VALUES(-1);  -- fails\n\u003c/pre\u003e\n\u003cp\u003eWhen an operator or function of the underlying type is applied to a domain value, the domain is automatically down-cast to the underlying type. Thus, for example, the result of \u003ccode class=\"literal\"\u003emytable.id - 1\u003c/code\u003e is considered to be of type \u003ccode class=\"type\"\u003einteger\u003c/code\u003e not \u003ccode class=\"type\"\u003eposint\u003c/code\u003e. We could write \u003ccode class=\"literal\"\u003e(mytable.id - 1)::posint\u003c/code\u003e to cast the result back to \u003ccode class=\"type\"\u003eposint\u003c/code\u003e, causing the domain's constraints to be rechecked. In this case, that would result in an error if the expression had been applied to an \u003ccode class=\"structfield\"\u003eid\u003c/code\u003e value of 1. Assigning a value of the underlying type to a field or variable of the domain type is allowed without writing an explicit cast, but the domain's constraints will be checked.\u003c/p\u003e\n\u003cp\u003eFor additional information see \u003ca class=\"xref\" href=\"/docs/18/sql-createdomain.html\" title=\"CREATE DOMAIN\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE DOMAIN\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/div\u003e","related":[],"sections":[]}},"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}
