mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
Add PL/Python functions for quoting strings
Add functions plpy.quote_ident, plpy.quote_literal, plpy.quote_nullable, which wrap the equivalent SQL functions. To be able to propagate char * constness properly, make the argument of quote_literal_cstr() const char *. This also makes it more consistent with quote_identifier(). Jan Urbański, reviewed by Hitoshi Harada, some refinements by Peter Eisentraut
This commit is contained in:
@ -997,6 +997,23 @@ $$ LANGUAGE plpythonu;
|
||||
<xref linkend="guc-client-min-messages"> configuration
|
||||
variables. See <xref linkend="runtime-config"> for more information.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Another set of utility functions are
|
||||
<literal>plpy.quote_literal(<replaceable>string</>)</literal>,
|
||||
<literal>plpy.quote_nullable(<replaceable>string</>)</literal>, and
|
||||
<literal>plpy.quote_ident(<replaceable>string</>)</literal>. They
|
||||
are equivalent to the built-in quoting functions described in <xref
|
||||
linkend="functions-string">. They are useful when constructing
|
||||
ad-hoc queries. A PL/Python equivalent of dynamic SQL from <xref
|
||||
linkend="plpgsql-quote-literal-example"> would be:
|
||||
<programlisting>
|
||||
plpy.execute("UPDATE tbl SET %s = %s where key = %s" % (
|
||||
plpy.quote_ident(colname),
|
||||
plpy.quote_nullable(newvalue),
|
||||
plpy.quote_literal(keyvalue)))
|
||||
</programlisting>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="plpython-envar">
|
||||
|
Reference in New Issue
Block a user