gpt4 book ai didi

python - 如何使用 SQLAlchemy 连接到 Amazon Redshift 中的集群?

转载 作者:太空狗 更新时间:2023-10-30 02:42:57 25 4
gpt4 key购买 nike

在 Amazon Redshift 的 Getting Started Guide 中,它提到您可以利用与 PostgreSQL 兼容的 SQL 客户端工具连接到您的 Amazon Redshift 集群。

在教程中,他们使用 SQL Workbench/J 客户端,但我想使用 python(尤其是 SQLAlchemy)。我找到了 related question ,但问题是它没有详细介绍连接到 Redshift 集群的 python 脚本。

我已经能够通过 SQL Workbench/J 连接到集群,因为我有 JDBC URL 以及我的用户名和密码,但我不确定如何连接到 SQLAlchemy。

基于此documentation ,我尝试了以下方法:

from sqlalchemy import create_engine
engine = create_engine('jdbc:redshift://shippy.cx6x1vnxlk55.us-west-2.redshift.amazonaws.com:5439/shippy')

错误:

Could not parse rfc1738 URL from string 'jdbc:redshift://shippy.cx6x1vnxlk55.us-west-2.redshift.amazonaws.com:5439/shippy'

最佳答案

我不认为 SQL Alchemy “天生”了解 Redshift。您需要更改 JDBC“URL”字符串以使用 postgres

jdbc:postgres://shippy.cx6x1vnxlk55.us-west-2.redshift.amazonaws.com:5439/shippy

或者,您可能想尝试使用 sqlalchemy-redshift使用他们提供的说明。

关于python - 如何使用 SQLAlchemy 连接到 Amazon Redshift 中的集群?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35004936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com