]> 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:06 +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 4e1cddcd7cf916e093120cf24560a71e503ec8a8..1f58a0d8456d88a0a53c68996c2c3385d6b38332 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 42ec19c20654e4f2a064e953d73703830c29c2b1..35f3352529000927be759b1db181b3f3c6deb0a3 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'