File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -251,6 +251,7 @@ def create_and_load_postgres_datetz(conn):
251
251
Table ,
252
252
insert ,
253
253
)
254
+ from sqlalchemy .engine import Engine
254
255
255
256
metadata = MetaData ()
256
257
datetz = Table ("datetz" , metadata , Column ("DateColWithTz" , DateTime (timezone = True )))
@@ -263,10 +264,17 @@ def create_and_load_postgres_datetz(conn):
263
264
},
264
265
]
265
266
stmt = insert (datetz ).values (datetz_data )
266
- with conn .begin ():
267
- datetz .drop (conn , checkfirst = True )
268
- datetz .create (bind = conn )
269
- conn .execute (stmt )
267
+ if isinstance (conn , Engine ):
268
+ with conn .connect () as conn :
269
+ with conn .begin ():
270
+ datetz .drop (conn , checkfirst = True )
271
+ datetz .create (bind = conn )
272
+ conn .execute (stmt )
273
+ else :
274
+ with conn .begin ():
275
+ datetz .drop (conn , checkfirst = True )
276
+ datetz .create (bind = conn )
277
+ conn .execute (stmt )
270
278
271
279
# "2000-01-01 00:00:00-08:00" should convert to
272
280
# "2000-01-01 08:00:00"
You can’t perform that action at this time.
0 commit comments