postgresql_16:9.6.18.1 hstore External Representation
PostgreSQL 16 > Appendixes > Additional Supplied Modules and Extensions > hstore — hstore key/value datatype > hstore External Representation
The text representation of an hstore, used for input and output, includes zero or more *key* => *value* pairs separated by commas. Some examples: k => v foo => bar, baz => whatever "1-a" => "anything at all" The order of the pairs is not significant (and may not be reproduced on output). Whitespace between pairs or around the => sign is ignored. Double-quote keys and values that include whitespace, commas, =s or >s. To include a double quote or a backslash in a key or value, escape it with a backslash.
Each key in an hstore is unique. If you declare an hstore with duplicate keys, only one will be stored in the hstore and there is no guarantee as to which will be kept: SELECT 'a=>1,a=>2'::hstore; hstore ---------- "a"=>"1"
A value (but not a key) can be an SQL NULL. For example: key => NULL The NULL keyword is case-insensitive. Double-quote the NULL to treat it as the ordinary string “NULL”.
Note
Keep in mind that the hstore text format, when used for input, applies *before* any required quoting or escaping. If you are passing an hstore literal via a parameter, then no additional processing is needed. But if you're passing it as a quoted literal constant, then any single-quote characters and (depending on the setting of the standard_conforming_strings configuration parameter) backslash characters need to be escaped correctly. See (see postgresql_16:3.1.1.2) for more on the handling of string constants.
On output, double quotes always surround keys and values, even when it's not strictly necessary.