CHAR, TEXT, FLOAT, NUMERIC, \
DATE, BOOLEAN
+_DECIMAL_TYPES = (1700, 1231)
+_FLOAT_TYPES = (700, 701, 1021, 1022)
+
+
class REAL(sqltypes.Float):
__visit_name__ = "REAL"
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)
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')
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)
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