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

查看:214
本文介绍了如何使用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。您需要更改JDBC URL字符串以使用 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天全站免登陆