Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save glassresistor/99ae14fb5679564e1444db09b7a0daf0 to your computer and use it in GitHub Desktop.

Select an option

Save glassresistor/99ae14fb5679564e1444db09b7a0daf0 to your computer and use it in GitHub Desktop.
from sqlalchemy import create_engine
columns = ['flame_retardants',]
engine = create_engine('postgresql:///your_user')
def make_sql(column):
#x21 = 'update tedx set %s=1 where %s="X"' % (column, column)
#null20 = 'update tedx set %s=0 where %s is null"' % (column, column)
sql = "alter table tedx alter %s type bool using case when %s='X' then TRUE else FALSE END;" % (column, column)
engine.execute(sql)
return engine.execute('select * from tedx;')
sql_commands = list(map(make_sql, columns))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment