From: Mike Bayer Date: Fri, 20 Jun 2014 21:58:06 +0000 (-0400) Subject: - Added a new type :class:`.postgresql.OID` to the Postgresql dialect. X-Git-Tag: rel_0_9_5~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=634127c3fce9e723b62617e5600e78d83eb2553e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Added a new type :class:`.postgresql.OID` to the Postgresql dialect. While "oid" is generally a private type within PG that is not exposed in modern versions, there are some PG use cases such as large object support where these types might be exposed, as well as within some user-reported schema reflection use cases. fixes #3002 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 0b4546a914..f1b2211e95 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,16 @@ .. changelog:: :version: 0.9.5 + .. change:: + :tags: enhancement, postgresql + :tickets: 3002 + + Added a new type :class:`.postgresql.OID` to the Postgresql dialect. + While "oid" is generally a private type within PG that is not exposed + in modern versions, there are some PG use cases such as large object + support where these types might be exposed, as well as within some + user-reported schema reflection use cases. + .. change:: :tags: bug, orm :tickets: 3080 diff --git a/doc/build/dialects/postgresql.rst b/doc/build/dialects/postgresql.rst index ab281db859..15b1fff9f1 100644 --- a/doc/build/dialects/postgresql.rst +++ b/doc/build/dialects/postgresql.rst @@ -15,7 +15,7 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect:: from sqlalchemy.dialects.postgresql import \ ARRAY, BIGINT, BIT, BOOLEAN, BYTEA, CHAR, CIDR, DATE, \ DOUBLE_PRECISION, ENUM, FLOAT, HSTORE, INET, INTEGER, \ - INTERVAL, JSON, MACADDR, NUMERIC, REAL, SMALLINT, TEXT, TIME, \ + INTERVAL, JSON, MACADDR, NUMERIC, OID, REAL, SMALLINT, TEXT, TIME, \ TIMESTAMP, UUID, VARCHAR, INT4RANGE, INT8RANGE, NUMRANGE, \ DATERANGE, TSRANGE, TSTZRANGE, TSVECTOR @@ -78,6 +78,8 @@ construction arguments, are as follows: .. autoclass:: MACADDR :members: __init__ +.. autoclass:: OID + :members: __init__ .. autoclass:: REAL :members: __init__ diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py index 180e9fc7e4..d1c768186d 100644 --- a/lib/sqlalchemy/dialects/postgresql/__init__.py +++ b/lib/sqlalchemy/dialects/postgresql/__init__.py @@ -10,7 +10,7 @@ base.dialect = psycopg2.dialect from .base import \ INTEGER, BIGINT, SMALLINT, VARCHAR, CHAR, TEXT, NUMERIC, FLOAT, REAL, \ - INET, CIDR, UUID, BIT, MACADDR, DOUBLE_PRECISION, TIMESTAMP, TIME, \ + INET, CIDR, UUID, BIT, MACADDR, OID, DOUBLE_PRECISION, TIMESTAMP, TIME, \ DATE, BYTEA, BOOLEAN, INTERVAL, ARRAY, ENUM, dialect, array, Any, All, \ TSVECTOR from .constraints import ExcludeConstraint @@ -21,7 +21,7 @@ from .ranges import INT4RANGE, INT8RANGE, NUMRANGE, DATERANGE, TSRANGE, \ __all__ = ( 'INTEGER', 'BIGINT', 'SMALLINT', 'VARCHAR', 'CHAR', 'TEXT', 'NUMERIC', - 'FLOAT', 'REAL', 'INET', 'CIDR', 'UUID', 'BIT', 'MACADDR', + 'FLOAT', 'REAL', 'INET', 'CIDR', 'UUID', 'BIT', 'MACADDR', 'OID', 'DOUBLE_PRECISION', 'TIMESTAMP', 'TIME', 'DATE', 'BYTEA', 'BOOLEAN', 'INTERVAL', 'ARRAY', 'ENUM', 'dialect', 'Any', 'All', 'array', 'HSTORE', 'hstore', 'INT4RANGE', 'INT8RANGE', 'NUMRANGE', 'DATERANGE', diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 92467ad39a..64292b1333 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -409,6 +409,15 @@ class MACADDR(sqltypes.TypeEngine): PGMacAddr = MACADDR +class OID(sqltypes.TypeEngine): + """Provide the Postgresql OID type. + + .. versionadded:: 0.9.5 + + """ + __visit_name__ = "OID" + + class TIMESTAMP(sqltypes.TIMESTAMP): def __init__(self, timezone=False, precision=None): super(TIMESTAMP, self).__init__(timezone=timezone) @@ -1080,6 +1089,7 @@ ischema_names = { 'bit': BIT, 'bit varying': BIT, 'macaddr': MACADDR, + 'oid': OID, 'double precision': DOUBLE_PRECISION, 'timestamp': TIMESTAMP, 'timestamp with time zone': TIMESTAMP, @@ -1353,6 +1363,9 @@ class PGTypeCompiler(compiler.GenericTypeCompiler): def visit_MACADDR(self, type_): return "MACADDR" + def visit_OID(self, type_): + return "OID" + def visit_FLOAT(self, type_): if not type_.precision: return "FLOAT" diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 1bfa8c4b7a..d70a0a52f1 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -320,6 +320,19 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults): finally: metadata.drop_all() +class OIDTest(fixtures.TestBase): + __only_on__ = 'postgresql' + + @testing.provide_metadata + def test_reflection(self): + metadata = self.metadata + Table('table', metadata, Column('x', Integer), + Column('y', postgresql.OID)) + metadata.create_all() + m2 = MetaData() + t2 = Table('table', m2, autoload_with=testing.db, autoload=True) + assert isinstance(t2.c.y.type, postgresql.OID) + class NumericInterpretationTest(fixtures.TestBase): __only_on__ = 'postgresql'