.. automethod:: execute
:param query: The query to execute.
- :type query: `!str`, `!bytes`, or `sql.Composable`
+ :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
:param params: The parameters to pass to the query, if any.
:type params: Sequence or Mapping
:param prepare: Force (`!True`) or disallow (`!False`) preparation of
See :ref:`query-parameters` for all the details about executing
queries.
+ .. versionchanged:: 3.1
+
+ The `query` argument must be a `~typing.StringLiteral`. If you
+ need to compose a query dynamically, please use `sql.SQL` and
+ related objects.
+
+ See :pep:`675` for details.
+
.. automethod:: executemany
:param query: The query to execute
- :type query: `!str`, `!bytes`, or `sql.Composable`
+ :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
:param params_seq: The parameters to pass to the query
:type params_seq: Sequence of Sequences or Mappings
:param returning: If `!True`, fetch the results of the queries executed
.. automethod:: copy
:param statement: The copy operation to execute
- :type statement: `!str`, `!bytes`, or `sql.Composable`
+ :type statement: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
:param params: The parameters to pass to the statement, if any.
:type params: Sequence or Mapping
.. automethod:: mogrify
:param query: The query to execute.
- :type query: `!str`, `!bytes`, or `sql.Composable`
+ :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
:param params: The parameters to pass to the query, if any.
:type params: Sequence or Mapping
.. automethod:: execute
:param query: The query to execute.
- :type query: `!str`, `!bytes`, or `sql.Composable`
+ :type query: `!str`, `!bytes`, `sql.SQL`, or `sql.Composed`
:param params: The parameters to pass to the query, if any.
:type params: Sequence or Mapping
:param binary: Specify whether the server shoul return data in binary
at :ref:`how Psycopg converts data types <types-adaptation>`.
+Using `LiteralString` in queries
+--------------------------------
+
+The `~Cursor.execute()` method and similar should only receive a literal
+string as input, according to :pep:`675`.
+
+If you need to compose a query dynamically you should use `sql.SQL` and
+similar methods.
+
+At the time of writing the feature is experimental and only checked by the
+Pyre_ checker.
+
+.. _Pyre: https://pyre-check.org/
+
+
.. index::
pair: Binary; Parameters