@@ -192,7 +192,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
192192 FROM v_catalog.columns
193193 where table_name = '{table_name}'
194194 {schema_conditional}
195- UNION ALL
195+ UNION
196196 SELECT
197197 column_name,
198198 data_type,
@@ -202,15 +202,49 @@ def get_columns(self, connection, table_name, schema=None, **kw):
202202 where table_name = '{table_name}'
203203 {schema_conditional}
204204 """ .format (table_name = table_name , schema_conditional = schema_conditional )
205- return [
206- {
207- 'name' : row .column_name ,
208- 'type' : self .ischema_names [row .data_type .upper ().split ('(' )[0 ]],
209- 'nullable' : row .is_nullable ,
210- 'default' : row .column_default ,
211- 'primary_key' : row .column_name in primary_key_columns
212- } for row in connection .execute (column_select )
213- ]
205+ colobjs = []
206+ for row in connection .execute (column_select ):
207+ colobj = self ._get_column_info (
208+ row .column_name ,
209+ row .data_type ,
210+ row .is_nullable ,
211+ row .column_default ,
212+ (row .column_name in primary_key_columns )
213+ )
214+ if colobj :
215+ colobjs .append (colobj )
216+ return colobjs
217+
218+ def _get_column_info (self , name , data_type , is_nullable , default , is_primary_key ):
219+ m = re .match (r'(\w+)(?:\((\d+)(?:,(\d+))?\))?' , data_type )
220+ if not m :
221+ raise ValueError ("data type string not parseable for type name and optional parameters: %s" % data_type )
222+ typename = m .group (1 ).upper ()
223+ typeobj = self .ischema_names [typename ]
224+ typeargs = []
225+ typekwargs = {}
226+ for arg_group in (2 , 3 ):
227+ try :
228+ param = m .group (arg_group )
229+ if param :
230+ typeargs .append (int (param ))
231+ except (TypeError , ValueError ):
232+ pass
233+
234+ if any (tz_string in typename for tz_string in ('TIMEZONE' , 'TIME ZONE' , 'TIMESTAMPTZ' )):
235+ typekwargs ['timezone' ] = True
236+
237+ if callable (typeobj ):
238+ typeobj = typeobj (* typeargs , ** typekwargs )
239+
240+ return {
241+ 'name' : name ,
242+ 'type' : typeobj ,
243+ 'nullable' : is_nullable ,
244+ 'default' : default ,
245+ 'primary_key' : is_primary_key
246+ }
247+
214248
215249 @reflection .cache
216250 def get_unique_constraints (self , connection , table_name , schema = None , ** kw ):
0 commit comments