summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py4
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pg8000.py11
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg2.py10
-rw-r--r--test/dialect/test_postgresql.py9
4 files changed, 20 insertions, 14 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index dcdaa3c7b..312ae9aa8 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -80,6 +80,10 @@ from sqlalchemy.types import INTEGER, BIGINT, SMALLINT, VARCHAR, \
CHAR, TEXT, FLOAT, NUMERIC, \
DATE, BOOLEAN
+_DECIMAL_TYPES = (1700, 1231)
+_FLOAT_TYPES = (700, 701, 1021, 1022)
+
+
class REAL(sqltypes.Float):
__visit_name__ = "REAL"
diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py
index c822e37a5..862c915aa 100644
--- a/lib/sqlalchemy/dialects/postgresql/pg8000.py
+++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py
@@ -26,23 +26,24 @@ from sqlalchemy import util, exc
from sqlalchemy import processors
from sqlalchemy import types as sqltypes
from sqlalchemy.dialects.postgresql.base import PGDialect, \
- PGCompiler, PGIdentifierPreparer, PGExecutionContext
+ PGCompiler, PGIdentifierPreparer, PGExecutionContext,\
+ _DECIMAL_TYPES, _FLOAT_TYPES
class _PGNumeric(sqltypes.Numeric):
def result_processor(self, dialect, coltype):
if self.asdecimal:
- if coltype in (700, 701, 1021, 1022):
+ if coltype in _FLOAT_TYPES:
return processors.to_decimal_processor_factory(decimal.Decimal)
- elif coltype in (1700, 1231):
+ elif coltype in _DECIMAL_TYPES:
# pg8000 returns Decimal natively for 1700
return None
else:
raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
else:
- if coltype in (700, 701, 1021, 1022):
+ if coltype in _FLOAT_TYPES:
# pg8000 returns float natively for 701
return None
- elif coltype in (1700, 1231):
+ elif coltype in _DECIMAL_TYPES:
return processors.to_float
else:
raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
index 45d1bf29e..2a51a7239 100644
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
@@ -68,7 +68,7 @@ from sqlalchemy.sql import operators as sql_operators
from sqlalchemy import types as sqltypes
from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, \
PGIdentifierPreparer, PGExecutionContext, \
- ENUM, ARRAY
+ ENUM, ARRAY, _DECIMAL_TYPES, _FLOAT_TYPES
logger = logging.getLogger('sqlalchemy.dialects.postgresql')
@@ -80,18 +80,18 @@ class _PGNumeric(sqltypes.Numeric):
def result_processor(self, dialect, coltype):
if self.asdecimal:
- if coltype in (700, 701, 1021, 1022):
+ if coltype in _FLOAT_TYPES:
return processors.to_decimal_processor_factory(decimal.Decimal)
- elif coltype in (1700, 1231):
+ elif coltype in _DECIMAL_TYPES:
# pg8000 returns Decimal natively for 1700
return None
else:
raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
else:
- if coltype in (700, 701, 1021, 1022):
+ if coltype in _FLOAT_TYPES:
# pg8000 returns float natively for 701
return None
- elif coltype in (1700, 1231):
+ elif coltype in _DECIMAL_TYPES:
return processors.to_float
else:
raise exc.InvalidRequestError("Unknown PG numeric type: %d" % coltype)
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py
index bcf8ac956..14814bc20 100644
--- a/test/dialect/test_postgresql.py
+++ b/test/dialect/test_postgresql.py
@@ -1326,11 +1326,12 @@ class MiscTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
exception_cls = eng.dialect.dbapi.ProgrammingError
assert_raises(exception_cls, eng.execute, "show transaction isolation level")
- @testing.only_on('postgresql+psycopg2',
- "this assertion isn't used on others, "
- "except pg8000 which circumvents it")
+ @testing.fails_on('+zxjdbc',
+ "psycopg2/pg8000 specific assertion")
+ @testing.fails_on('pypostgresql',
+ "psycopg2/pg8000 specific assertion")
def test_numeric_raise(self):
- stmt = text("select 'hi' as hi", typemap={'hi':Numeric})
+ stmt = text("select cast('hi' as char) as hi", typemap={'hi':Numeric})
assert_raises(
exc.InvalidRequestError,
testing.db.execute, stmt