summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-09 10:08:44 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-09 10:08:44 -0500
commit1939d26282b27b4b264c6930830a7991ed83917a (patch)
tree9e2ff9c38937b85ed5307e8d4cf9b7dd86f97591 /doc/src
parentd9f7f5d32f201bec61fef8104aafcb77cecb4dcb (diff)
Add test scaffolding for soft error reporting from input functions.
pg_input_is_valid() returns boolean, while pg_input_error_message() returns the primary error message if the input is bad, or NULL if the input is OK. The main reason for having two functions is so that we can test both the details-wanted and the no-details-wanted code paths. Although these are primarily designed with testing in mind, it could well be that they'll be useful to end users as well. This patch is mostly by me, but it owes very substantial debt to earlier work by Nikita Glukhov, Andrew Dunstan, and Amul Sul. Thanks to Andres Freund for review. Discussion: https://postgr.es/m/3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/func.sgml101
1 files changed, 101 insertions, 0 deletions
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index e57ffce9713..ad31fdb737c 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -24683,6 +24683,107 @@ SELECT collation for ('foo' COLLATE "de_DE");
</sect2>
+ <sect2 id="functions-info-validity">
+ <title>Data Validity Checking Functions</title>
+
+ <para>
+ The functions shown in <xref linkend="functions-info-validity-table"/>
+ can be helpful for checking validity of proposed input data.
+ </para>
+
+ <table id="functions-info-validity-table">
+ <title>Data Validity Checking Functions</title>
+ <tgroup cols="1">
+ <thead>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ Function
+ </para>
+ <para>
+ Description
+ </para>
+ <para>
+ Example(s)
+ </para></entry>
+ </row>
+ </thead>
+
+ <tbody>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <indexterm>
+ <primary>pg_input_is_valid</primary>
+ </indexterm>
+ <function>pg_input_is_valid</function> (
+ <parameter>string</parameter> <type>text</type>,
+ <parameter>type</parameter> <type>text</type>
+ )
+ <returnvalue>boolean</returnvalue>
+ </para>
+ <para>
+ Tests whether the given <parameter>string</parameter> is valid
+ input for the specified data type, returning true or false.
+ </para>
+ <para>
+ This function will only work as desired if the data type's input
+ function has been updated to report invalid input as
+ a <quote>soft</quote> error. Otherwise, invalid input will abort
+ the transaction, just as if the string had been cast to the type
+ directly.
+ </para>
+ <para>
+ <literal>pg_input_is_valid('42', 'integer')</literal>
+ <returnvalue>t</returnvalue>
+ </para>
+ <para>
+ <literal>pg_input_is_valid('42000000000', 'integer')</literal>
+ <returnvalue>f</returnvalue>
+ </para>
+ <para>
+ <literal>pg_input_is_valid('1234.567', 'numeric(7,4)')</literal>
+ <returnvalue>f</returnvalue>
+ </para></entry>
+ </row>
+ <row>
+ <entry role="func_table_entry"><para role="func_signature">
+ <indexterm>
+ <primary>pg_input_error_message</primary>
+ </indexterm>
+ <function>pg_input_error_message</function> (
+ <parameter>string</parameter> <type>text</type>,
+ <parameter>type</parameter> <type>text</type>
+ )
+ <returnvalue>text</returnvalue>
+ </para>
+ <para>
+ Tests whether the given <parameter>string</parameter> is valid
+ input for the specified data type; if not, return the error
+ message that would have been thrown. If the input is valid, the
+ result is NULL. The inputs are the same as
+ for <function>pg_input_is_valid</function>.
+ </para>
+ <para>
+ This function will only work as desired if the data type's input
+ function has been updated to report invalid input as
+ a <quote>soft</quote> error. Otherwise, invalid input will abort
+ the transaction, just as if the string had been cast to the type
+ directly.
+ </para>
+ <para>
+ <literal>pg_input_error_message('42000000000', 'integer')</literal>
+ <returnvalue>value "42000000000" is out of range for type integer</returnvalue>
+ </para>
+ <para>
+ <literal>pg_input_error_message('1234.567', 'numeric(7,4)')</literal>
+ <returnvalue>numeric field overflow</returnvalue>
+ </para></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ </sect2>
+
<sect2 id="functions-info-snapshot">
<title>Transaction ID and Snapshot Information Functions</title>