成功连接到Redshift后,我试图确保我的表存在于集群中。这是我正在运行的代码:
from sqlalchemy.engine import URL, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Boolean, SMALLINT, Column
Base = declarative_base()
class Table(Base):
__tablename__ = "a_table"
id = Column(SMALLINT, primary_key=True)
a_boolean_column = Column(Boolean)
# example values
engine = create_engine(
URL.create(
drivername="postgresql+psycopg2",
username="username",
password="password",
host="127.0.0.1",
port=5439,
database="dev",
)
)
base.metadata.create_all(engine)
我得到以下错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) syntax error at or near "a_boolean_column"
LINE 12: a_boolean_column BOOLEAN,
^
[SQL:
CREATE TABLE a_table (
id INTEGER NOT NULL,
a_boolean_column BOOLEAN,
PRIMARY KEY (id),
)
]
我已经尝试使用sqlalchemy
的BOOLEAN
数据类型,并尝试设置默认值,但都失败了。
版本:
SQLAlchemy==1.4.47
sqlalchemy-redshift==0.8.13
我们必须使用URL.create
的drivername
参数强制sqlalchemy
使用正确的引擎:
# example values
engine = create_engine(
URL.create(
drivername="redshift+psycopg2",
username="username",
password="password",
host="127.0.0.1",
port=5439,
database="dev",
)
)
在drivername="postgresql+psycopg2"
之前,当它应该是drivername="redshift+psycopg2"
。