@@ -5,37 +5,73 @@ Frequently Asked Questions
5
5
==========================
6
6
7
7
Does asyncpg support DB-API?
8
- No. DB-API is a synchronous API, while asyncpg is based
9
- around an asynchronous I/O model. Thus, full drop-in compatibility
10
- with DB-API is not possible and we decided to design asyncpg API
11
- in a way that is better aligned with PostgreSQL architecture and
12
- terminology. We will release a synchronous DB-API-compatible version
13
- of asyncpg at some point in the future.
8
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9
+
10
+ No. DB-API is a synchronous API, while asyncpg is based
11
+ around an asynchronous I/O model. Thus, full drop-in compatibility
12
+ with DB-API is not possible and we decided to design asyncpg API
13
+ in a way that is better aligned with PostgreSQL architecture and
14
+ terminology. We will release a synchronous DB-API-compatible version
15
+ of asyncpg at some point in the future.
16
+
14
17
15
18
Can I use asyncpg with SQLAlchemy ORM?
16
- Short answer: no. asyncpg uses asynchronous execution model
17
- and API, which is fundamentally incompatible with SQLAlchemy.
18
- However, it is possible to use asyncpg and SQLAlchemy Core
19
- with the help of a third-party adapter, such as asyncpgsa _.
19
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
+
21
+ Short answer: no. asyncpg uses asynchronous execution model
22
+ and API, which is fundamentally incompatible with SQLAlchemy.
23
+ However, it is possible to use asyncpg and SQLAlchemy Core
24
+ with the help of a third-party adapter, such as asyncpgsa _.
25
+
20
26
21
27
Can I use dot-notation with :class: `asyncpg.Record `? It looks cleaner.
22
- We decided against making :class: `asyncpg.Record ` a named tuple
23
- because we want to keep the ``Record `` method namespace separate
24
- from the column namespace.
28
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29
+
30
+ We decided against making :class: `asyncpg.Record ` a named tuple
31
+ because we want to keep the ``Record `` method namespace separate
32
+ from the column namespace.
33
+
25
34
26
35
Why can't I use a :ref: `cursor <asyncpg-api-cursor >` outside of a transaction?
27
- Cursors created by a call to
28
- :meth: `Connection.cursor() <asyncpg.connection.Connection.cursor> ` or
29
- :meth: `PreparedStatement.cursor() \
30
- <asyncpg.prepared_stmt.PreparedStatement.cursor> `
31
- cannot be used outside of a transaction. Any such attempt will result in
32
- ``InterfaceError ``.
33
- To create a cursor usable outside of a transaction, use the
34
- ``DECLARE ... CURSOR WITH HOLD `` SQL statement directly.
36
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37
+
38
+ Cursors created by a call to
39
+ :meth: `Connection.cursor() <asyncpg.connection.Connection.cursor> ` or
40
+ :meth: `PreparedStatement.cursor() \
41
+ <asyncpg.prepared_stmt.PreparedStatement.cursor> `
42
+ cannot be used outside of a transaction. Any such attempt will result in
43
+ ``InterfaceError ``.
44
+ To create a cursor usable outside of a transaction, use the
45
+ ``DECLARE ... CURSOR WITH HOLD `` SQL statement directly.
46
+
47
+
48
+ .. _asyncpg-prepared-stmt-errors :
49
+
50
+ Why am I getting prepared statement errors?
51
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
+
53
+ If you are getting intermittent ``prepared statement "__asyncpg_stmt_xx__"
54
+ does not exist `` or ``prepared statement “__asyncpg_stmt_xx__”
55
+ already exists `` errors, you are most likely not connecting to the
56
+ PostgreSQL server directly, but via
57
+ `pgbouncer <https://pgbouncer.github.io/ >`_. pgbouncer, when
58
+ in the ``"transaction" `` or ``"statement" `` pooling mode, does not support
59
+ prepared statements. You have two options:
60
+
61
+ * if you are using pgbouncer for connection pooling to a single server,
62
+ switch to the :ref: `connection pool <asyncpg-connection-pool >`
63
+ functionality provided by asyncpg, it is a much better option for this
64
+ purpose;
65
+
66
+ * if you have no option of avoiding the use of pgbouncer, then you need to
67
+ switch pgbouncer's ``pool_mode `` to ``session ``.
68
+
35
69
36
70
Why do I get ``PostgresSyntaxError `` when using ``expression IN $1 ``?
37
- ``expression IN $1 `` is not a valid PostgreSQL syntax. To check
38
- a value against a sequence use ``expression = any($1::mytype[]) ``,
39
- where ``mytype `` is the array element type.
71
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
+
73
+ ``expression IN $1 `` is not a valid PostgreSQL syntax. To check
74
+ a value against a sequence use ``expression = any($1::mytype[]) ``,
75
+ where ``mytype `` is the array element type.
40
76
41
77
.. _asyncpgsa : https://github.com/CanopyTax/asyncpgsa
0 commit comments