TimescaleDB:是否可以从Python调用"create_hypertable"? [英] TimescaleDB: Is it possible to call 'create_hypertable' from Python?

查看:546
本文介绍了TimescaleDB:是否可以从Python调用"create_hypertable"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Postgres中动态创建TimescaleDB表,因为我正在处理随时间变化的数据源(财务提要,可能是100,可能是1000),并且我希望每个数据源有一个表.

I want to create TimescaleDB tables in Postgres on the fly as I'm dealing with data sources that change (financial feeds, so could be 100, could be 1000) over time and I want one table per data source.

我可以从Python创建表没有问题,但是当我调用SELECT create_hypertable(test_table1, time)时会抛出错误.从pSQL执行该查询当然可以正常工作,因此看起来好像无法通过psycopg2使用timescale API吗?

I can create the tables no problem from Python, but when I call SELECT create_hypertable(test_table1, time) it throws an error. The same query seems to work fine when executed from pSQL of course, so it looks like the timescale API isn't available via psycopg2 perhaps?

  • Python 3.6.4
  • psycopg2-binary-2.7.4(安装了标志:--no-binary:all:)
  • Postgres:10.3
  • Timescaledb:0.8.0-2
  • MacOS:10.13.3
db.query("CREATE TABLE test_table1 (time TIMESTAMP NOT NULL, name CHAR(100) NOT NULL")
db.query("SELECT create_hypertable('test_table1', 'time')")

错误:

2018-03-05 11:45:36,901 [MainThread] [ERROR]函数create_hypertable(未知,未知)不存在
第1行:SELECT create_hypertable('temp_table1','time')
. . . . . . . . . . . . . . ^
提示:没有函数与给定的名称和参数类型匹配.您可能需要添加显式类型强制转换.

2018-03-05 11:45:36,901 [MainThread ] [ERROR] function create_hypertable(unknown, unknown) does not exist
LINE 1: SELECT create_hypertable('temp_table1', 'time')
. . . . . . . . . . . . . . ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

有人知道当前是否有这项工作吗?我错过了一些简单的事情吗?还是有另一项服务可以替代支持动态创建的时标功能?

Does anyone know if there currently anyway to making this work? Have I missed something simple? Or is there another service that can replace timescale functionality that supports being dynamically created?

推荐答案

该输出表明您尚未在运行create_hypertable的数据库上安装TimescaleDB扩展名.确保您运行:

That output implies that you haven't installed the TimescaleDB extension on the database you're running create_hypertable on. Make sure you run:

CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

在运行create_hypertable之前在数据库上

.要确保已创建扩展,请运行以下查询:

on your database before running create_hypertable. To ensure the extension has been created, run the following query:

select * from pg_extension;

psycopg对此没有任何影响,因为.query()调用似乎只是在执行传递给它的原始SQL.确保您的psycopg客户端连接到与最初安装TimescaleDB扩展名的客户端相同的数据库.

psycopg shouldn't have any effect on this as the .query() call appears to just be executing the raw SQL you pass it. Make sure your psycopg client is connected to the same database as the one you initially installed the TimescaleDB extension on.

这篇关于TimescaleDB:是否可以从Python调用"create_hypertable"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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