def register_date_typecasters(connection):
 def cast_date(value, cursor):
  return value
 cursor = connection.cursor()
 cursor.execute('SELECT NULL::date')
 date_oid = cursor.description[0][1]
 cursor.execute('SELECT NULL::timestamp')
 timestamp_oid = cursor.description[0][1]
 cursor.execute('SELECT NULL::timestamp with time zone')
 timestamptz_oid = cursor.description[0][1]
 oids = (date_oid, timestamp_oid, timestamptz_oid)
 new_type = psycopg2.extensions.new_type(oids, 'DATE', cast_date)
 psycopg2.extensions.register_type(new_type)

def register_date_typecasters ( connection ) : def cast_date ( value , cursor ) : return value cursor = connection . cursor ( ) cursor . execute ( 'SELECT NULL::date' ) date_oid = cursor . description [ 0 ] [ 1 ] cursor . execute ( 'SELECT NULL::timestamp' ) timestamp_oid = cursor . description [ 0 ] [ 1 ] cursor . execute ( 'SELECT NULL::timestamp with time zone' ) timestamptz_oid = cursor . description [ 0 ] [ 1 ] oids = ( date_oid , timestamp_oid , timestamptz_oid ) new_type = psycopg2 . extensions . new_type ( oids , 'DATE' , cast_date ) psycopg2 . extensions . register_type ( new_type )
casts date and timestamp values to string .