python - 使用 Dask 从 postgresql 导入数据

标签 python postgresql dask

因此,我在 postgres 中存储了一个大型(7GB)数据集,我正在尝试将其导入到 Dask 中。我正在尝试 read_sql_table 函数,但不断收到 ArgumentErrors。

我在 postgres 中的信息如下:

  • 数据库是“my_database”
  • 架构是“公开的”
  • 数据表是“表”
  • 用户名是“fred”
  • 密码是“my_pass”
  • postgres 中的索引是“idx”

我正在尝试让这段代码正常工作:

df = dd.read_sql_table('public.table', 'jdbc:postgresql://localhost/my_database?user=fred&password=my_pass', index_col='idx') 

我的格式是否错误?

最佳答案

我终于能够通过使用 psycopg2 弄清楚它。答案如下:

df = dd.read_sql_table('table', 'postgresql+psycopg2://postgres:fred@localhost/my_database', index_col = 'idx')

此外,我必须在 postgres 表中创建一个不同的索引。原始索引需要是一个完整的单独列。我在 Postgres 中使用以下行执行此操作:

alter table table add idx serial;

关于python - 使用 Dask 从 postgresql 导入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67694082/

相关文章:

python - 如果我想在 Apache 上使用 pylons 应用程序,我应该使用 mod_wsgi 还是代理来粘贴?

python - setupclass 中的 django_db 标记问题

sql - 加入靶场的最佳方式?

postgresql - Postgresql 上的 Btree 详细信息

python - 在 dask 中设置 Parquet 输出文件的大小

amazon-ec2 - 使用 dask labextensiontion 连接到远程集群

python - 尽管我的类和属性似乎设置正确,但在 Python : Why AttributeError, 中练习继承?

python - Pyqt QTablewidget 自动换行

postgresql - 使用 Postgres Plus 开发并部署 Postgresql Open Source?

dask - 如何使用 dask/fastparquet 从多个目录读取多个 Parquet 文件(具有相同的架构)