2

When I run print CreateTable(question) after the following code I get an error, and it is because it is not compiling correctly because of ARRAY which is something specific to postgres. How do I get it to compile the correct CREATE script? Where do I enter dialect-related compiling information?

from sqlalchemy import Table, Column, Integer, String, ForeignKey, MetaData
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy.schema import CreateTable

metadata=MetaData()

user = Table('user', metadata,
            Column('id', Integer, primary_key=True)
            )

question = Table('question', metadata,
            Column('id', Integer, primary_key=True),
            Column('description', String),
            Column('answers', ARRAY(String))
            )
user3659451
  • 1,913
  • 9
  • 30
  • 43

1 Answers1

2
from sqlalchemy.dialects import postgresql
print CreateTable(question).compile(dialect=postgresql.dialect())

CREATE TABLE question (
id SERIAL NOT NULL, 
description VARCHAR, 
answers VARCHAR[], 
PRIMARY KEY (id)
)
user3659451
  • 1,913
  • 9
  • 30
  • 43