如何将 Power BI 连接到 PostgreSQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45071920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to connect Power BI to PostgreSQL
提问by let_there_be_light
I want get data into Power BI desktop from PostgreSQL (on my local machine). I tried the solution given here (Installing ngpsql to use PostgreSQL in PowerBI), but it did not work.
我想将数据从 PostgreSQL(在我的本地机器上)导入 Power BI 桌面。我尝试了此处给出的解决方案(安装 ngpsql 以在 PowerBI 中使用 PostgreSQL),但没有奏效。
Basically, I installed the latest version of ngpsql(3.2.4) with the option to install to GAC. However, I'm getting the same error in Power BI saying that the connector requires one or more additional components.
基本上,我安装了最新版本的 ngpsql(3.2.4),并带有安装到 GAC 的选项。但是,我在 Power BI 中遇到了同样的错误,说连接器需要一个或多个附加组件。
Am I missing any steps? I looked online but did not find any recent documentation on this.
我错过了任何步骤吗?我在网上查看,但没有找到任何关于此的最新文档。
Any help is very much appreciated.
很感谢任何形式的帮助。
Thanks
谢谢
回答by Rigoberta Raviolini
Three ways :
三种方式:
1 - The ngpsql way does work if your follow the comment of Lavande:
1 -该ngpsql方式做工作,如果你后续的评论Lavande:
- Install npgsql as Administrator (since the DLL would be pushed to GAC);
- During the installation stage, enabled "Npgsql GAC Installation";
- Restart the PC
- 以管理员身份安装 npgsql(因为 DLL 会被推送到 GAC);
- 在安装阶段,启用“Npgsql GAC安装”;
- 重启电脑
2 - With ODBC, i used this walk-through
2 - 使用 ODBC,我使用了这个演练
- install ODBC connector here
- start it and create a new connection (DSN)
- in Power BI, get data, ODBC,PostGreSQL, no options
- enter the credentials.
- select the table(s) of interest.
- 在此处安装 ODBC 连接器
- 启动它并创建一个新连接(DSN)
- 在 Power BI 中,获取数据,ODBC,PostGreSQL,无选项
- 输入凭据。
- 选择感兴趣的表。
3 - With the M query language.
3 - 使用 M 查询语言。
Nota: the Power BI community posts ? well, ...
注意:Power BI 社区帖子?好, ...
回答by Rafael
Another option to solve this problem is to create a Python script to connect to Postgresql.
解决这个问题的另一个选择是创建一个 Python 脚本来连接到 Postgresql。
Using a script like this:
使用这样的脚本:
import psycopg2
import pandas as pd
con = psycopg2.connect(host='localhost', database='Your DataBase',
user='user', password='password')
cur = con.cursor()
cur.execute('Your Query')
data = cur.fetchall()
df = pd.DataFrame(data, columns=['Your Columns'])