{"Entry":{"collection":"type","key":"xml","name":"xml","aliases":[],"metadata":{"aliases":[],"category":"Other built-in types","content_hash":"0485a264475b4e36c5c4c4be0c9dd6f563aeaa43c5a284bc242649ccc68bb4a0","imported_at":"2026-09-30T00:40:37.109812+08:00","name":"xml","name_zh":"","slug":"xml","summary":"XML data"}},"Definition":{"Collection":"type","Key":"xml","SourceDatabase":"center","Version":"18","SourceTable":"data_type","SourceKey":"xml","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"aliases":[],"casts":[{"castcontext":"a","castfunc":"0","castmethod":"b","castsource":"xml","casttarget":"text"},{"castcontext":"e","castfunc":"xml","castmethod":"f","castsource":"text","casttarget":"xml"},{"castcontext":"a","castfunc":"0","castmethod":"b","castsource":"xml","casttarget":"varchar"},{"castcontext":"e","castfunc":"xml","castmethod":"f","castsource":"varchar","casttarget":"xml"},{"castcontext":"a","castfunc":"0","castmethod":"b","castsource":"xml","casttarget":"bpchar"},{"castcontext":"e","castfunc":"xml","castmethod":"f","castsource":"bpchar","casttarget":"xml"}],"catalog":{"array_type_name":"_xml","array_type_oid":"143","descr":"XML content","oid":"142","typacl":"_null_","typalign":"i","typanalyze":"-","typarray":"0","typbasetype":"0","typbyval":"f","typcategory":"U","typcollation":"0","typdefault":"_null_","typdefaultbin":"_null_","typdelim":"','","typelem":"0","typinput":"xml_in","typisdefined":"t","typispreferred":"f","typlen":"-1","typmodin":"-","typmodout":"-","typname":"xml","typnamespace":"pg_catalog","typndims":"0","typnotnull":"f","typoutput":"xml_out","typowner":"POSTGRES","typreceive":"xml_recv","typrelid":"0","typsend":"xml_send","typstorage":"x","typsubscript":"-","typtype":"b","typtypmod":"-1"},"comparison_data":{"aliases":[],"casts":[{"castcontext":"a","castfunc":"0","castmethod":"b","castsource":"xml","casttarget":"bpchar"},{"castcontext":"a","castfunc":"0","castmethod":"b","castsource":"xml","casttarget":"text"},{"castcontext":"a","castfunc":"0","castmethod":"b","castsource":"xml","casttarget":"varchar"},{"castcontext":"e","castfunc":"xml","castmethod":"f","castsource":"bpchar","casttarget":"xml"},{"castcontext":"e","castfunc":"xml","castmethod":"f","castsource":"text","casttarget":"xml"},{"castcontext":"e","castfunc":"xml","castmethod":"f","castsource":"varchar","casttarget":"xml"}],"catalog":{"array_type_name":"_xml","typacl":"_null_","typalign":"i","typanalyze":"-","typarray":"_xml","typbasetype":"0","typbyval":"f","typcategory":"U","typcollation":"0","typdefault":"_null_","typdefaultbin":"_null_","typdelim":",","typelem":"0","typinput":"xml_in","typisdefined":"t","typispreferred":"f","typlen":"-1","typmodin":"-","typmodout":"-","typname":"xml","typndims":"0","typnotnull":"f","typoutput":"xml_out","typreceive":"xml_recv","typrelid":"0","typsend":"xml_send","typstorage":"x","typsubscript":"-","typtype":"b","typtypmod":"-1"},"facts":[{"label":"Catalog name","value":"pg_catalog.xml"},{"label":"Declared length","value":"Variable length (varlena)"},{"label":"Input function","value":"xml_in"},{"label":"Output function","value":"xml_out"},{"label":"Storage strategy","value":"extended"},{"label":"Type OID","value":"142"},{"label":"Type kind","value":"Base type"}],"operator_classes":[],"operators":[],"ranges":[]},"comparison_hash":"be0324e2842d599b3e15e8f3a3fd3eb024ab5b684df76ace6afa9e3562470bce","coverage":"source inventory; exact declared input types for operator classes","description":["XML data"],"facts":[{"label":"Catalog name","value":"pg_catalog.xml"},{"label":"Type OID","value":"142"},{"label":"Type kind","value":"Base type"},{"label":"Declared length","value":"Variable length (varlena)"},{"label":"Storage strategy","value":"extended"},{"label":"Input function","value":"xml_in"},{"label":"Output function","value":"xml_out"}],"manual_documentation":"dedicated family chapter","manual_html":"\u003cdiv class=\"sect1\" id=\"DATATYPE-XML\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e8.13. XML Type \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type can be used to store XML data. Its advantage over storing XML data in a \u003ccode class=\"type\"\u003etext\u003c/code\u003e field is that it checks the input values for well-formedness, and there are support functions to perform type-safe operations on it; see \u003ca class=\"xref\" href=\"/docs/18/functions-xml.html\" title=\"9.15. XML Functions\"\u003eSection 9.15\u003c/a\u003e. Use of this data type requires the installation to have been built with \u003ccode class=\"command\"\u003econfigure --with-libxml\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e type can store well-formed \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003edocuments\u003c/span\u003e”\u003c/span\u003e, as defined by the XML standard, as well as \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003econtent\u003c/span\u003e”\u003c/span\u003e fragments, which are defined by reference to the more permissive \u003ca class=\"ulink\" href=\"https://www.w3.org/TR/2010/REC-xpath-datamodel-20101214/#DocumentNode\"\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003edocument node\u003c/span\u003e”\u003c/span\u003e\u003c/a\u003e of the XQuery and XPath data model. Roughly, this means that content fragments can have more than one top-level element or character node. The expression \u003ccode class=\"literal\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003exmlvalue\u003c/code\u003e\u003c/em\u003e IS DOCUMENT\u003c/code\u003e can be used to evaluate whether a particular \u003ccode class=\"type\"\u003exml\u003c/code\u003e value is a full document or only a content fragment.\u003c/p\u003e\n\u003cp\u003eLimits and compatibility notes for the \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type can be found in \u003ca class=\"xref\" href=\"/docs/18/xml-limits-conformance.html\" title=\"D.3. XML Limits and Conformance to SQL/XML\"\u003eSection D.3\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-XML-CREATING\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.13.1. Creating XML Values \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eTo produce a value of type \u003ccode class=\"type\"\u003exml\u003c/code\u003e from character data, use the function \u003ccode class=\"function\"\u003exmlparse\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eXMLPARSE ( { DOCUMENT | CONTENT } \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e)\n\u003c/pre\u003e\n\u003cp\u003eExamples:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eXMLPARSE (DOCUMENT '\u0026lt;?xml version=\"1.0\"?\u0026gt;\u0026lt;book\u0026gt;\u0026lt;title\u0026gt;Manual\u0026lt;/title\u0026gt;\u0026lt;chapter\u0026gt;...\u0026lt;/chapter\u0026gt;\u0026lt;/book\u0026gt;')\nXMLPARSE (CONTENT 'abc\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;\u0026lt;bar\u0026gt;foo\u0026lt;/bar\u0026gt;')\n\u003c/pre\u003e\n\u003cp\u003eWhile this is the only way to convert character strings into XML values according to the SQL standard, the PostgreSQL-specific syntaxes:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003exml '\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;'\n'\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;'::xml\n\u003c/pre\u003e\n\u003cp\u003ecan also be used.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e type does not validate input values against a document type declaration (DTD), even when the input value specifies a DTD. There is also currently no built-in support for validating against other XML schema languages such as XML Schema.\u003c/p\u003e\n\u003cp\u003eThe inverse operation, producing a character string value from \u003ccode class=\"type\"\u003exml\u003c/code\u003e, uses the function \u003ccode class=\"function\"\u003exmlserialize\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eXMLSERIALIZE ( { DOCUMENT | CONTENT } \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e AS \u003cem class=\"replaceable\"\u003e\u003ccode\u003etype\u003c/code\u003e\u003c/em\u003e [ [ NO ] INDENT ] )\n\u003c/pre\u003e\n\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003etype\u003c/code\u003e\u003c/em\u003e can be \u003ccode class=\"type\"\u003echaracter\u003c/code\u003e, \u003ccode class=\"type\"\u003echaracter varying\u003c/code\u003e, or \u003ccode class=\"type\"\u003etext\u003c/code\u003e (or an alias for one of those). Again, according to the SQL standard, this is the only way to convert between type \u003ccode class=\"type\"\u003exml\u003c/code\u003e and character types, but PostgreSQL also allows you to simply cast the value.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"literal\"\u003eINDENT\u003c/code\u003e option causes the result to be pretty-printed, while \u003ccode class=\"literal\"\u003eNO INDENT\u003c/code\u003e (which is the default) just emits the original input string. Casting to a character type likewise produces the original string.\u003c/p\u003e\n\u003cp\u003eWhen a character string value is cast to or from type \u003ccode class=\"type\"\u003exml\u003c/code\u003e without going through \u003ccode class=\"type\"\u003eXMLPARSE\u003c/code\u003e or \u003ccode class=\"type\"\u003eXMLSERIALIZE\u003c/code\u003e, respectively, the choice of \u003ccode class=\"literal\"\u003eDOCUMENT\u003c/code\u003e versus \u003ccode class=\"literal\"\u003eCONTENT\u003c/code\u003e is determined by the \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eXML option\u003c/span\u003e”\u003c/span\u003e  session configuration parameter, which can be set using the standard command:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eSET XML OPTION { DOCUMENT | CONTENT };\n\u003c/pre\u003e\n\u003cp\u003eor the more PostgreSQL-like syntax\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eSET xmloption TO { DOCUMENT | CONTENT };\n\u003c/pre\u003e\n\u003cp\u003eThe default is \u003ccode class=\"literal\"\u003eCONTENT\u003c/code\u003e, so all forms of XML data are allowed.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-XML-ENCODING-HANDLING\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.13.2. Encoding Handling \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eCare must be taken when dealing with multiple character encodings on the client, server, and in the XML data passed through them. When using the text mode to pass queries to the server and query results to the client (which is the normal mode), PostgreSQL converts all character data passed between the client and the server and vice versa to the character encoding of the respective end; see \u003ca class=\"xref\" href=\"/docs/18/multibyte.html\" title=\"23.3. Character Set Support\"\u003eSection 23.3\u003c/a\u003e. This includes string representations of XML values, such as in the above examples. This would ordinarily mean that encoding declarations contained in XML data can become invalid as the character data is converted to other encodings while traveling between client and server, because the embedded encoding declaration is not changed. To cope with this behavior, encoding declarations contained in character strings presented for input to the \u003ccode class=\"type\"\u003exml\u003c/code\u003e type are \u003cspan class=\"emphasis\"\u003e\u003cem\u003eignored\u003c/em\u003e\u003c/span\u003e, and content is assumed to be in the current server encoding. Consequently, for correct processing, character strings of XML data must be sent from the client in the current client encoding. It is the responsibility of the client to either convert documents to the current client encoding before sending them to the server, or to adjust the client encoding appropriately. On output, values of type \u003ccode class=\"type\"\u003exml\u003c/code\u003e will not have an encoding declaration, and clients should assume all data is in the current client encoding.\u003c/p\u003e\n\u003cp\u003eWhen using binary mode to pass query parameters to the server and query results back to the client, no encoding conversion is performed, so the situation is different. In this case, an encoding declaration in the XML data will be observed, and if it is absent, the data will be assumed to be in UTF-8 (as required by the XML standard; note that PostgreSQL does not support UTF-16). On output, data will have an encoding declaration specifying the client encoding, unless the client encoding is UTF-8, in which case it will be omitted.\u003c/p\u003e\n\u003cp\u003eNeedless to say, processing XML data with PostgreSQL will be less error-prone and more efficient if the XML data encoding, client encoding, and server encoding are the same. Since XML data is internally processed in UTF-8, computations will be most efficient if the server encoding is also UTF-8.\u003c/p\u003e\n\u003cdiv class=\"caution\"\u003e\n\u003ch3 class=\"title\"\u003eCaution\u003c/h3\u003e\n\u003cp\u003eSome XML-related functions may not work at all on non-ASCII data when the server encoding is not UTF-8. This is known to be an issue for \u003ccode class=\"function\"\u003exmltable()\u003c/code\u003e and \u003ccode class=\"function\"\u003expath()\u003c/code\u003e in particular.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-XML-ACCESSING-XML-VALUES\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.13.3. Accessing XML Values \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type is unusual in that it does not provide any comparison operators. This is because there is no well-defined and universally useful comparison algorithm for XML data. One consequence of this is that you cannot retrieve rows by comparing an \u003ccode class=\"type\"\u003exml\u003c/code\u003e column against a search value. XML values should therefore typically be accompanied by a separate key field such as an ID. An alternative solution for comparing XML values is to convert them to character strings first, but note that character string comparison has little to do with a useful XML comparison method.\u003c/p\u003e\n\u003cp\u003eSince there are no comparison operators for the \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type, it is not possible to create an index directly on a column of this type. If speedy searches in XML data are desired, possible workarounds include casting the expression to a character string type and indexing that, or indexing an XPath expression. Of course, the actual query would have to be adjusted to search by the indexed expression.\u003c/p\u003e\n\u003cp\u003eThe text-search functionality in PostgreSQL can also be used to speed up full-document searches of XML data. The necessary preprocessing support is, however, not yet available in the PostgreSQL distribution.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","manual_path":"datatype-xml.html","operator_classes":[],"operators":[],"ranges":[],"related":[{"label":"pg_type catalog","url":"/wiki/catalog/pg_type/?v=18"},{"label":"pg_cast catalog","url":"/wiki/catalog/pg_cast/?v=18"},{"label":"pg_operator catalog","url":"/wiki/catalog/pg_operator/?v=18"},{"label":"pg_opclass catalog","url":"/wiki/catalog/pg_opclass/?v=18"},{"label":"Arrays","url":"/wiki/type/arrays/?v=18"}],"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":[],"signature":"xml","sources":[{"label":"PostgreSQL 18 English manual","path":"datatype-xml.html","sha256":"061fc2295b7b69be704f0a741b8decd10ad721059f871fb0243c669bb54d7822","url":"/docs/18/datatype-xml.html"},{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"ManualEvidence":{"manual_path":"datatype-xml.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":"datatype-xml.html","sha256":"061fc2295b7b69be704f0a741b8decd10ad721059f871fb0243c669bb54d7822","url":"/docs/18/datatype-xml.html"},{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"MeasuredEvidence":{}},"Text":{"Collection":"type","Key":"xml","SourceDatabase":"center","Version":"18","Locale":"en","Title":"xml","Summary":"XML data","BodyHTML":"\u003cdiv id=\"DATATYPE-XML\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2\u003e8.13. XML Type \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode\u003exml\u003c/code\u003e data type can be used to store XML data. Its advantage over storing XML data in a \u003ccode\u003etext\u003c/code\u003e field is that it checks the input values for well-formedness, and there are support functions to perform type-safe operations on it; see \u003ca href=\"/docs/18/functions-xml.html\" rel=\"nofollow\"\u003eSection 9.15\u003c/a\u003e. Use of this data type requires the installation to have been built with \u003ccode\u003econfigure --with-libxml\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode\u003exml\u003c/code\u003e type can store well-formed \u003cspan\u003e“\u003cspan\u003edocuments\u003c/span\u003e”\u003c/span\u003e, as defined by the XML standard, as well as \u003cspan\u003e“\u003cspan\u003econtent\u003c/span\u003e”\u003c/span\u003e fragments, which are defined by reference to the more permissive \u003ca href=\"https://www.w3.org/TR/2010/REC-xpath-datamodel-20101214/#DocumentNode\" rel=\"nofollow\"\u003e\u003cspan\u003e“\u003cspan\u003edocument node\u003c/span\u003e”\u003c/span\u003e\u003c/a\u003e of the XQuery and XPath data model. Roughly, this means that content fragments can have more than one top-level element or character node. The expression \u003ccode\u003e\u003cem\u003e\u003ccode\u003exmlvalue\u003c/code\u003e\u003c/em\u003e IS DOCUMENT\u003c/code\u003e can be used to evaluate whether a particular \u003ccode\u003exml\u003c/code\u003e value is a full document or only a content fragment.\u003c/p\u003e\n\u003cp\u003eLimits and compatibility notes for the \u003ccode\u003exml\u003c/code\u003e data type can be found in \u003ca href=\"/docs/18/xml-limits-conformance.html\" rel=\"nofollow\"\u003eSection D.3\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv id=\"DATATYPE-XML-CREATING\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003e8.13.1. Creating XML Values \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eTo produce a value of type \u003ccode\u003exml\u003c/code\u003e from character data, use the function \u003ccode\u003exmlparse\u003c/code\u003e:\u003c/p\u003e\n\u003cpre\u003eXMLPARSE ( { DOCUMENT | CONTENT } \u003cem\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e)\n\u003c/pre\u003e\n\u003cp\u003eExamples:\u003c/p\u003e\n\u003cpre\u003eXMLPARSE (DOCUMENT \u0026#39;\u0026lt;?xml version=\u0026#34;1.0\u0026#34;?\u0026gt;\u0026lt;book\u0026gt;\u0026lt;title\u0026gt;Manual\u0026lt;/title\u0026gt;\u0026lt;chapter\u0026gt;...\u0026lt;/chapter\u0026gt;\u0026lt;/book\u0026gt;\u0026#39;)\nXMLPARSE (CONTENT \u0026#39;abc\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;\u0026lt;bar\u0026gt;foo\u0026lt;/bar\u0026gt;\u0026#39;)\n\u003c/pre\u003e\n\u003cp\u003eWhile this is the only way to convert character strings into XML values according to the SQL standard, the PostgreSQL-specific syntaxes:\u003c/p\u003e\n\u003cpre\u003exml \u0026#39;\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;\u0026#39;\n\u0026#39;\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;\u0026#39;::xml\n\u003c/pre\u003e\n\u003cp\u003ecan also be used.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode\u003exml\u003c/code\u003e type does not validate input values against a document type declaration (DTD), even when the input value specifies a DTD. There is also currently no built-in support for validating against other XML schema languages such as XML Schema.\u003c/p\u003e\n\u003cp\u003eThe inverse operation, producing a character string value from \u003ccode\u003exml\u003c/code\u003e, uses the function \u003ccode\u003exmlserialize\u003c/code\u003e:\u003c/p\u003e\n\u003cpre\u003eXMLSERIALIZE ( { DOCUMENT | CONTENT } \u003cem\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e AS \u003cem\u003e\u003ccode\u003etype\u003c/code\u003e\u003c/em\u003e [ [ NO ] INDENT ] )\n\u003c/pre\u003e\n\u003cp\u003e\u003cem\u003e\u003ccode\u003etype\u003c/code\u003e\u003c/em\u003e can be \u003ccode\u003echaracter\u003c/code\u003e, \u003ccode\u003echaracter varying\u003c/code\u003e, or \u003ccode\u003etext\u003c/code\u003e (or an alias for one of those). Again, according to the SQL standard, this is the only way to convert between type \u003ccode\u003exml\u003c/code\u003e and character types, but PostgreSQL also allows you to simply cast the value.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode\u003eINDENT\u003c/code\u003e option causes the result to be pretty-printed, while \u003ccode\u003eNO INDENT\u003c/code\u003e (which is the default) just emits the original input string. Casting to a character type likewise produces the original string.\u003c/p\u003e\n\u003cp\u003eWhen a character string value is cast to or from type \u003ccode\u003exml\u003c/code\u003e without going through \u003ccode\u003eXMLPARSE\u003c/code\u003e or \u003ccode\u003eXMLSERIALIZE\u003c/code\u003e, respectively, the choice of \u003ccode\u003eDOCUMENT\u003c/code\u003e versus \u003ccode\u003eCONTENT\u003c/code\u003e is determined by the \u003cspan\u003e“\u003cspan\u003eXML option\u003c/span\u003e”\u003c/span\u003e  session configuration parameter, which can be set using the standard command:\u003c/p\u003e\n\u003cpre\u003eSET XML OPTION { DOCUMENT | CONTENT };\n\u003c/pre\u003e\n\u003cp\u003eor the more PostgreSQL-like syntax\u003c/p\u003e\n\u003cpre\u003eSET xmloption TO { DOCUMENT | CONTENT };\n\u003c/pre\u003e\n\u003cp\u003eThe default is \u003ccode\u003eCONTENT\u003c/code\u003e, so all forms of XML data are allowed.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"DATATYPE-XML-ENCODING-HANDLING\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003e8.13.2. Encoding Handling \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eCare must be taken when dealing with multiple character encodings on the client, server, and in the XML data passed through them. When using the text mode to pass queries to the server and query results to the client (which is the normal mode), PostgreSQL converts all character data passed between the client and the server and vice versa to the character encoding of the respective end; see \u003ca href=\"/docs/18/multibyte.html\" rel=\"nofollow\"\u003eSection 23.3\u003c/a\u003e. This includes string representations of XML values, such as in the above examples. This would ordinarily mean that encoding declarations contained in XML data can become invalid as the character data is converted to other encodings while traveling between client and server, because the embedded encoding declaration is not changed. To cope with this behavior, encoding declarations contained in character strings presented for input to the \u003ccode\u003exml\u003c/code\u003e type are \u003cspan\u003e\u003cem\u003eignored\u003c/em\u003e\u003c/span\u003e, and content is assumed to be in the current server encoding. Consequently, for correct processing, character strings of XML data must be sent from the client in the current client encoding. It is the responsibility of the client to either convert documents to the current client encoding before sending them to the server, or to adjust the client encoding appropriately. On output, values of type \u003ccode\u003exml\u003c/code\u003e will not have an encoding declaration, and clients should assume all data is in the current client encoding.\u003c/p\u003e\n\u003cp\u003eWhen using binary mode to pass query parameters to the server and query results back to the client, no encoding conversion is performed, so the situation is different. In this case, an encoding declaration in the XML data will be observed, and if it is absent, the data will be assumed to be in UTF-8 (as required by the XML standard; note that PostgreSQL does not support UTF-16). On output, data will have an encoding declaration specifying the client encoding, unless the client encoding is UTF-8, in which case it will be omitted.\u003c/p\u003e\n\u003cp\u003eNeedless to say, processing XML data with PostgreSQL will be less error-prone and more efficient if the XML data encoding, client encoding, and server encoding are the same. Since XML data is internally processed in UTF-8, computations will be most efficient if the server encoding is also UTF-8.\u003c/p\u003e\n\u003cdiv\u003e\n\u003ch3\u003eCaution\u003c/h3\u003e\n\u003cp\u003eSome XML-related functions may not work at all on non-ASCII data when the server encoding is not UTF-8. This is known to be an issue for \u003ccode\u003exmltable()\u003c/code\u003e and \u003ccode\u003expath()\u003c/code\u003e in particular.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"DATATYPE-XML-ACCESSING-XML-VALUES\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003e8.13.3. Accessing XML Values \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003ccode\u003exml\u003c/code\u003e data type is unusual in that it does not provide any comparison operators. This is because there is no well-defined and universally useful comparison algorithm for XML data. One consequence of this is that you cannot retrieve rows by comparing an \u003ccode\u003exml\u003c/code\u003e column against a search value. XML values should therefore typically be accompanied by a separate key field such as an ID. An alternative solution for comparing XML values is to convert them to character strings first, but note that character string comparison has little to do with a useful XML comparison method.\u003c/p\u003e\n\u003cp\u003eSince there are no comparison operators for the \u003ccode\u003exml\u003c/code\u003e data type, it is not possible to create an index directly on a column of this type. If speedy searches in XML data are desired, possible workarounds include casting the expression to a character string type and indexing that, or indexing an XPath expression. Of course, the actual query would have to be adjusted to search by the indexed expression.\u003c/p\u003e\n\u003cp\u003eThe text-search functionality in PostgreSQL can also be used to speed up full-document searches of XML data. The necessary preprocessing support is, however, not yet available in the PostgreSQL distribution.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"5e68463983f7f525e8e1ebda0e9025fec9be8d0cdd6efe1e48c48f46ab508312","Payload":{"description":["XML data"],"manual_html":"\u003cdiv class=\"sect1\" id=\"DATATYPE-XML\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e8.13. XML Type \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type can be used to store XML data. Its advantage over storing XML data in a \u003ccode class=\"type\"\u003etext\u003c/code\u003e field is that it checks the input values for well-formedness, and there are support functions to perform type-safe operations on it; see \u003ca class=\"xref\" href=\"/docs/18/functions-xml.html\" title=\"9.15. XML Functions\"\u003eSection 9.15\u003c/a\u003e. Use of this data type requires the installation to have been built with \u003ccode class=\"command\"\u003econfigure --with-libxml\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e type can store well-formed \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003edocuments\u003c/span\u003e”\u003c/span\u003e, as defined by the XML standard, as well as \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003econtent\u003c/span\u003e”\u003c/span\u003e fragments, which are defined by reference to the more permissive \u003ca class=\"ulink\" href=\"https://www.w3.org/TR/2010/REC-xpath-datamodel-20101214/#DocumentNode\"\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003edocument node\u003c/span\u003e”\u003c/span\u003e\u003c/a\u003e of the XQuery and XPath data model. Roughly, this means that content fragments can have more than one top-level element or character node. The expression \u003ccode class=\"literal\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003exmlvalue\u003c/code\u003e\u003c/em\u003e IS DOCUMENT\u003c/code\u003e can be used to evaluate whether a particular \u003ccode class=\"type\"\u003exml\u003c/code\u003e value is a full document or only a content fragment.\u003c/p\u003e\n\u003cp\u003eLimits and compatibility notes for the \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type can be found in \u003ca class=\"xref\" href=\"/docs/18/xml-limits-conformance.html\" title=\"D.3. XML Limits and Conformance to SQL/XML\"\u003eSection D.3\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-XML-CREATING\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.13.1. Creating XML Values \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eTo produce a value of type \u003ccode class=\"type\"\u003exml\u003c/code\u003e from character data, use the function \u003ccode class=\"function\"\u003exmlparse\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eXMLPARSE ( { DOCUMENT | CONTENT } \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e)\n\u003c/pre\u003e\n\u003cp\u003eExamples:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eXMLPARSE (DOCUMENT '\u0026lt;?xml version=\"1.0\"?\u0026gt;\u0026lt;book\u0026gt;\u0026lt;title\u0026gt;Manual\u0026lt;/title\u0026gt;\u0026lt;chapter\u0026gt;...\u0026lt;/chapter\u0026gt;\u0026lt;/book\u0026gt;')\nXMLPARSE (CONTENT 'abc\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;\u0026lt;bar\u0026gt;foo\u0026lt;/bar\u0026gt;')\n\u003c/pre\u003e\n\u003cp\u003eWhile this is the only way to convert character strings into XML values according to the SQL standard, the PostgreSQL-specific syntaxes:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003exml '\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;'\n'\u0026lt;foo\u0026gt;bar\u0026lt;/foo\u0026gt;'::xml\n\u003c/pre\u003e\n\u003cp\u003ecan also be used.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e type does not validate input values against a document type declaration (DTD), even when the input value specifies a DTD. There is also currently no built-in support for validating against other XML schema languages such as XML Schema.\u003c/p\u003e\n\u003cp\u003eThe inverse operation, producing a character string value from \u003ccode class=\"type\"\u003exml\u003c/code\u003e, uses the function \u003ccode class=\"function\"\u003exmlserialize\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eXMLSERIALIZE ( { DOCUMENT | CONTENT } \u003cem class=\"replaceable\"\u003e\u003ccode\u003evalue\u003c/code\u003e\u003c/em\u003e AS \u003cem class=\"replaceable\"\u003e\u003ccode\u003etype\u003c/code\u003e\u003c/em\u003e [ [ NO ] INDENT ] )\n\u003c/pre\u003e\n\u003cp\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003etype\u003c/code\u003e\u003c/em\u003e can be \u003ccode class=\"type\"\u003echaracter\u003c/code\u003e, \u003ccode class=\"type\"\u003echaracter varying\u003c/code\u003e, or \u003ccode class=\"type\"\u003etext\u003c/code\u003e (or an alias for one of those). Again, according to the SQL standard, this is the only way to convert between type \u003ccode class=\"type\"\u003exml\u003c/code\u003e and character types, but PostgreSQL also allows you to simply cast the value.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"literal\"\u003eINDENT\u003c/code\u003e option causes the result to be pretty-printed, while \u003ccode class=\"literal\"\u003eNO INDENT\u003c/code\u003e (which is the default) just emits the original input string. Casting to a character type likewise produces the original string.\u003c/p\u003e\n\u003cp\u003eWhen a character string value is cast to or from type \u003ccode class=\"type\"\u003exml\u003c/code\u003e without going through \u003ccode class=\"type\"\u003eXMLPARSE\u003c/code\u003e or \u003ccode class=\"type\"\u003eXMLSERIALIZE\u003c/code\u003e, respectively, the choice of \u003ccode class=\"literal\"\u003eDOCUMENT\u003c/code\u003e versus \u003ccode class=\"literal\"\u003eCONTENT\u003c/code\u003e is determined by the \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eXML option\u003c/span\u003e”\u003c/span\u003e  session configuration parameter, which can be set using the standard command:\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eSET XML OPTION { DOCUMENT | CONTENT };\n\u003c/pre\u003e\n\u003cp\u003eor the more PostgreSQL-like syntax\u003c/p\u003e\n\u003cpre class=\"synopsis\"\u003eSET xmloption TO { DOCUMENT | CONTENT };\n\u003c/pre\u003e\n\u003cp\u003eThe default is \u003ccode class=\"literal\"\u003eCONTENT\u003c/code\u003e, so all forms of XML data are allowed.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-XML-ENCODING-HANDLING\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.13.2. Encoding Handling \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eCare must be taken when dealing with multiple character encodings on the client, server, and in the XML data passed through them. When using the text mode to pass queries to the server and query results to the client (which is the normal mode), PostgreSQL converts all character data passed between the client and the server and vice versa to the character encoding of the respective end; see \u003ca class=\"xref\" href=\"/docs/18/multibyte.html\" title=\"23.3. Character Set Support\"\u003eSection 23.3\u003c/a\u003e. This includes string representations of XML values, such as in the above examples. This would ordinarily mean that encoding declarations contained in XML data can become invalid as the character data is converted to other encodings while traveling between client and server, because the embedded encoding declaration is not changed. To cope with this behavior, encoding declarations contained in character strings presented for input to the \u003ccode class=\"type\"\u003exml\u003c/code\u003e type are \u003cspan class=\"emphasis\"\u003e\u003cem\u003eignored\u003c/em\u003e\u003c/span\u003e, and content is assumed to be in the current server encoding. Consequently, for correct processing, character strings of XML data must be sent from the client in the current client encoding. It is the responsibility of the client to either convert documents to the current client encoding before sending them to the server, or to adjust the client encoding appropriately. On output, values of type \u003ccode class=\"type\"\u003exml\u003c/code\u003e will not have an encoding declaration, and clients should assume all data is in the current client encoding.\u003c/p\u003e\n\u003cp\u003eWhen using binary mode to pass query parameters to the server and query results back to the client, no encoding conversion is performed, so the situation is different. In this case, an encoding declaration in the XML data will be observed, and if it is absent, the data will be assumed to be in UTF-8 (as required by the XML standard; note that PostgreSQL does not support UTF-16). On output, data will have an encoding declaration specifying the client encoding, unless the client encoding is UTF-8, in which case it will be omitted.\u003c/p\u003e\n\u003cp\u003eNeedless to say, processing XML data with PostgreSQL will be less error-prone and more efficient if the XML data encoding, client encoding, and server encoding are the same. Since XML data is internally processed in UTF-8, computations will be most efficient if the server encoding is also UTF-8.\u003c/p\u003e\n\u003cdiv class=\"caution\"\u003e\n\u003ch3 class=\"title\"\u003eCaution\u003c/h3\u003e\n\u003cp\u003eSome XML-related functions may not work at all on non-ASCII data when the server encoding is not UTF-8. This is known to be an issue for \u003ccode class=\"function\"\u003exmltable()\u003c/code\u003e and \u003ccode class=\"function\"\u003expath()\u003c/code\u003e in particular.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-XML-ACCESSING-XML-VALUES\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.13.3. Accessing XML Values \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type is unusual in that it does not provide any comparison operators. This is because there is no well-defined and universally useful comparison algorithm for XML data. One consequence of this is that you cannot retrieve rows by comparing an \u003ccode class=\"type\"\u003exml\u003c/code\u003e column against a search value. XML values should therefore typically be accompanied by a separate key field such as an ID. An alternative solution for comparing XML values is to convert them to character strings first, but note that character string comparison has little to do with a useful XML comparison method.\u003c/p\u003e\n\u003cp\u003eSince there are no comparison operators for the \u003ccode class=\"type\"\u003exml\u003c/code\u003e data type, it is not possible to create an index directly on a column of this type. If speedy searches in XML data are desired, possible workarounds include casting the expression to a character string type and indexing that, or indexing an XPath expression. Of course, the actual query would have to be adjusted to search by the indexed expression.\u003c/p\u003e\n\u003cp\u003eThe text-search functionality in PostgreSQL can also be used to speed up full-document searches of XML data. The necessary preprocessing support is, however, not yet available in the PostgreSQL distribution.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","related":[{"label":"pg_type catalog","url":"/wiki/catalog/pg_type/?v=18"},{"label":"pg_cast catalog","url":"/wiki/catalog/pg_cast/?v=18"},{"label":"pg_operator catalog","url":"/wiki/catalog/pg_operator/?v=18"},{"label":"pg_opclass catalog","url":"/wiki/catalog/pg_opclass/?v=18"},{"label":"Arrays","url":"/wiki/type/arrays/?v=18"}],"sections":[]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
