如何使用 SQLAlchemy 连接到 Amazon Redshift 中的集群? [英] How to connect to a cluster in Amazon Redshift using SQLAlchemy?

查看:46
本文介绍了如何使用 SQLAlchemy 连接到 Amazon Redshift 中的集群?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Amazon Redshift 的 入门指南中,它提到您可以利用与 PostgreSQL 兼容的 SQL 客户端工具连接到您的 Amazon Redshift 集群.

In Amazon Redshift's Getting Started Guide, it's mentioned that you can utilize SQL client tools that are compatible with PostgreSQL to connect to your Amazon Redshift Cluster.

在教程中,他们使用 SQL Workbench/J 客户端,但我想使用 python(特别是 SQLAlchemy).我发现了一个相关问题,但问题是它没有进入连接到 Redshift 集群的细节或 python 脚本.

In the tutorial, they utilize SQL Workbench/J client, but I'd like to utilize python (in particular SQLAlchemy). I've found a related question, but the issue is that it does not go into the detail or the python script that connects to the Redshift Cluster.

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

I've been able to connect to the cluster via SQL Workbench/J, since I have the JDBC URL, as well as my username and password, but I'm not sure how to connect with SQLAlchemy.

基于此文档,我尝试了以下操作:

Based on this documentation, I've tried the following:

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.您需要更改 JDBCURL"字符串以使用 postgres.

I don't think SQL Alchemy "natively" knows about Redshift. You need to change the JDBC "URL" string to use postgres.

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

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

Alternatively, you may want to try using sqlalchemy-redshift using the instructions they provide.

这篇关于如何使用 SQLAlchemy 连接到 Amazon Redshift 中的集群?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆