8
9
.. dialect:: postgresql+pg8000
11
:connectstring: postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...]
12
:url: http://pybrary.net/pg8000/
13
postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...]
14
:url: https://pythonhosted.org/pg8000/
17
pg8000 requires that the postgresql client encoding be
18
configured in the postgresql.conf file in order to use encodings
19
other than ascii. Set this value to the same value as the
20
"encoding" parameter on create_engine(), usually "utf-8".
25
Passing data from/to the Interval type is not supported as of
19
When communicating with the server, pg8000 uses the character set that the
20
server asks it to use (the client encoding). By default the client encoding is
21
the database's character set (chosen when the database is created), but the
22
client encoding can be changed in a number of ways (eg. setting CLIENT_ENCODING
25
Set the "encoding" parameter on create_engine(), to the same as the client
26
encoding, usually "utf-8".
28
.. _pg8000_isolation_level:
30
pg8000 Transaction Isolation Level
31
-------------------------------------
33
The pg8000 dialect offers the same isolation level settings as that
34
of the :ref:`psycopg2 <psycopg2_isolation_level>` dialect:
37
* ``READ UNCOMMITTED``
42
.. versionadded:: 0.9.5 support for AUTOCOMMIT isolation level when using
47
:ref:`postgresql_isolation_level`
49
:ref:`psycopg2_isolation_level`
29
53
from ... import util, exc
31
55
from ... import processors
32
56
from ... import types as sqltypes
33
from .base import PGDialect, \
34
PGCompiler, PGIdentifierPreparer, PGExecutionContext,\
35
_DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES
58
PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext,
59
_DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES)
38
62
class _PGNumeric(sqltypes.Numeric):
41
65
if coltype in _FLOAT_TYPES:
42
66
return processors.to_decimal_processor_factory(
44
self._effective_decimal_return_scale)
67
decimal.Decimal, self._effective_decimal_return_scale)
45
68
elif coltype in _DECIMAL_TYPES or coltype in _INT_TYPES:
46
69
# pg8000 returns Decimal natively for 1700
49
72
raise exc.InvalidRequestError(
50
"Unknown PG numeric type: %d" % coltype)
73
"Unknown PG numeric type: %d" % coltype)
52
75
if coltype in _FLOAT_TYPES:
53
76
# pg8000 returns float natively for 701
71
94
class PGCompiler_pg8000(PGCompiler):
72
95
def visit_mod_binary(self, binary, operator, **kw):
73
96
return self.process(binary.left, **kw) + " %% " + \
74
self.process(binary.right, **kw)
97
self.process(binary.right, **kw)
76
99
def post_process_text(self, text):
123
146
def is_disconnect(self, e, connection, cursor):
124
147
return "connection is closed" in str(e)
149
def set_isolation_level(self, connection, level):
150
level = level.replace('_', ' ')
152
if level == 'AUTOCOMMIT':
153
connection.connection.autocommit = True
154
elif level in self._isolation_lookup:
155
connection.connection.autocommit = False
156
cursor = connection.cursor()
158
"SET SESSION CHARACTERISTICS AS TRANSACTION "
159
"ISOLATION LEVEL %s" % level)
160
cursor.execute("COMMIT")
163
raise exc.ArgumentError(
164
"Invalid value '%s' for isolation_level. "
165
"Valid isolation levels for %s are %s or AUTOCOMMIT" %
166
(level, self.name, ", ".join(self._isolation_lookup))
126
169
dialect = PGDialect_pg8000