diff options
author | Gaëtan de Menten <gdementen@gmail.com> | 2010-02-13 22:53:39 +0000 |
---|---|---|
committer | Gaëtan de Menten <gdementen@gmail.com> | 2010-02-13 22:53:39 +0000 |
commit | 165609a190665f5453417c9c935a834714c7f5a5 (patch) | |
tree | 90d3d0da3f233cf6fc211f367eea0dba661b098e /lib/sqlalchemy/dialects/postgresql/psycopg2.py | |
parent | f2974ef3993e02646a2dfade5feb74afb78f370f (diff) | |
download | sqlalchemy-165609a190665f5453417c9c935a834714c7f5a5.tar.gz |
- Added an optional C extension to speed up the sql layer by
reimplementing the highest impact functions.
The actual speedups will depend heavily on your DBAPI and
the mix of datatypes used in your tables, and can vary from
a 50% improvement to more than 200%. It also provides a modest
(~20%) indirect improvement to ORM speed for large queries.
Note that it is *not* built/installed by default.
See README for installation instructions.
- The most common result processors conversion function were
moved to the new "processors" module. Dialect authors are
encouraged to use those functions whenever they correspond
to their needs instead of implementing custom ones.
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index bb6562dea..712124288 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -46,8 +46,11 @@ The following per-statement execution options are respected: """ -import decimal, random, re +import random, re +import decimal + from sqlalchemy import util +from sqlalchemy import processors from sqlalchemy.engine import base, default from sqlalchemy.sql import expression from sqlalchemy.sql import operators as sql_operators @@ -63,12 +66,7 @@ class _PGNumeric(sqltypes.Numeric): def result_processor(self, dialect, coltype): if self.asdecimal: if coltype in (700, 701): - def process(value): - if value is not None: - return decimal.Decimal(str(value)) - else: - return value - return process + return processors.to_decimal_processor_factory(decimal.Decimal) elif coltype == 1700: # pg8000 returns Decimal natively for 1700 return None @@ -79,12 +77,7 @@ class _PGNumeric(sqltypes.Numeric): # pg8000 returns float natively for 701 return None elif coltype == 1700: - def process(value): - if value is not None: - return float(value) - else: - return value - return process + return processors.to_float else: raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype) |