-1

I'm trying to create a table in Amazon Redshift with Flask, since you can't use models to create tables, how can I create them with SQL directly?

for example .execute ("CREATE TABLE ..."

Mehdi
  • 717
  • 1
  • 7
  • 21
dapdap
  • 61
  • 1
  • 2
  • 7
  • Have you looked at this redshift-sqlalchemy plugin? https://github.com/sqlalchemy-redshift/sqlalchemy-redshift. For creating tables you probably want to consider Alembic: https://alembic.sqlalchemy.org/en/latest/tutorial.html – Jon Feb 17 '20 at 14:12

1 Answers1

0

If you want to execute raw SQL queries in a Flask app, use SQLAlchemy's execute() method

result = db.engine.execute("<sql here>")

I would question your assumptions that you cannot use models (presumably from sql-alchemy) to create tables. I am not a Redshift user, but it seems that once the SQL connection is there, most standard SQL features would be available, and you can use tools like SQLAlchemy and Alembic to work with models instead of raw SQL. It appears there is already a SQLAlchemy plugin to help with Redshift connections.

Jon
  • 1,820
  • 2
  • 19
  • 43