Skip to content

Commit 49bba0b

Browse files
author
James William Pye
committed
Add an oid-to-sql predefined type names mapping.
And associate the datetime type Oids with the datetime.* types.
1 parent 8410c90 commit 49bba0b

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

postgresql/types.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
PostgreSQL types and identifiers
77
"""
88
import math
9+
import datetime
910
try:
1011
import xml.etree.cElementTree as etree
1112
except ImportError:
@@ -100,6 +101,38 @@
100101
ANYNONARRAYOID = 2776
101102
ANYENUMOID = 3500
102103

104+
oid_to_sql_name = {
105+
BPCHAROID : 'CHARACTER',
106+
VARCHAROID : 'CHARACTER VARYING',
107+
# *OID : 'CHARACTER LARGE OBJECT',
108+
109+
# SELECT X'0F' -> bit. XXX: Does bytea have any play here?
110+
#BITOID : 'BINARY',
111+
#BYTEAOID : 'BINARY VARYING',
112+
# *OID : 'BINARY LARGE OBJECT',
113+
114+
BOOLOID : 'BOOLEAN',
115+
116+
# exact numeric types
117+
INT2OID : 'SMALLINT',
118+
INT4OID : 'INTEGER',
119+
INT8OID : 'BIGINT',
120+
NUMERICOID : 'NUMERIC',
121+
122+
# approximate numeric types
123+
FLOAT4OID : 'REAL',
124+
FLOAT8OID : 'DOUBLE PRECISION',
125+
126+
# datetime types
127+
TIMEOID : 'TIME WITHOUT TIME ZONE',
128+
TIMETZOID : 'TIME WITH TIME ZONE',
129+
TIMESTAMPOID : 'TIMESTAMP WITHOUT TIME ZONE',
130+
TIMESTAMPTZOID : 'TIMESTAMP WITH TIME ZONE',
131+
DATEOID : 'DATE',
132+
133+
# interval types
134+
INTERVALOID : 'INTERVAL',
135+
}
103136

104137
oid_to_name = {
105138
RECORDOID : 'record',
@@ -263,7 +296,7 @@ def __len__(self):
263296

264297
def __add__(self, ob):
265298
return varbit(str(self) + str(ob))
266-
299+
267300
def __mul__(self, ob):
268301
return varbit(str(self) * ob)
269302

@@ -705,4 +738,12 @@ def __iter__(self):
705738

706739
FLOAT4OID: float,
707740
FLOAT8OID: float,
741+
742+
DATEOID: datetime.date,
743+
TIMESTAMPOID: datetime.datetime,
744+
TIMESTAMPTZOID: datetime.datetime,
745+
TIMEOID: datetime.time,
746+
TIMETZOID: datetime.time,
747+
748+
INTERVALOID: datetime.timedelta,
708749
}

0 commit comments

Comments
 (0)