]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added a new type :class:`.postgresql.OID` to the Postgresql dialect.
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Jun 2014 21:58:06 +0000 (17:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Jun 2014 21:58:35 +0000 (17:58 -0400)
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

doc/build/changelog/changelog_09.rst
doc/build/dialects/postgresql.rst
lib/sqlalchemy/dialects/postgresql/__init__.py
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_types.py

index 0b4546a914c3a4973f56e5116dbfd07e89dc9e6c..f1b2211e95f3d8a4a785f1ce3259721b8dd56e17 100644 (file)
 .. 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
index ab281db859890bd9908ea3eb7818e37d0d7da189..15b1fff9f10c1f8cea11747af9eb9076f4e022ca 100644 (file)
@@ -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__
index 180e9fc7e4b22696a968eddfda8c3de6f14d969a..d1c768186d014d8727fccd0996de3d2a7e87eefd 100644 (file)
@@ -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',
index 92467ad39af58173d3db365924b153c0bec746bb..64292b1333b74b46b7acd91bf03be6b1c4acb804 100644 (file)
@@ -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"
index 1bfa8c4b7a18acd1793f2283c97c8cb8190f8dcb..d70a0a52f1b47914901cbc155b9013e88e9a497a 100644 (file)
@@ -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'