通过SQL炼金术创建超表 [英] Creating Hypertables through SQL Alchemy

查看:103
本文介绍了通过SQL炼金术创建超表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前的项目在很大程度上依赖于SQL Alchemy进行表创建/数据插入.我们想切换到timescaledb的超级表,但是似乎推荐的创建超级表的方法是执行

Our current project relies heavily on SQL Alchemy for table creation/data insertion. We would like to switch to timescaledb's hypertables, but it seems the recommended way to create hypertables is by executing a

create_hypertable

命令.我需要能够动态创建表,因此对于创建的每个表手动执行此操作实际上不是一个选择.处理转换的一种方法是运行一个发送psycopg2命令的python脚本,将所有新创建的表转换为超表,但这似乎有点笨拙.在创建超表方面,timescaledb是否提供与SQL Alchemy的任何集成?

command. I need to be able to dynamically create tables, and so manually doing this for every table created is not really an option. One way of handling the conversion is to run a python script sending psycopg2 commands to convert all newly-created tables into hypertables, but this seems a little clumsy. Does timescaledb offer any integration with SQL Alchemy with regards to creating hypertables?

推荐答案

我们目前不提供与SQL Alchemy的任何特定集成(广泛或专门用于创建超表).我们一直很乐意听到新功能的要求,因此,如果您想在我们的Github上发布您的问题/用例,这将有助于我们更好地跟踪它,以备将来使用.

We currently do not offer any specific integrations with SQL Alchemy (broadly or specifically for creating hypertables). We are always interested in hearing new feature requests, so if you wanted to post your issue/use case on our Github it would help us keep better track of it for future work.

对您的用例可能有用的一件事是创建一个在创建表时执行的事件触发器.您必须检查它是否在正确的架构中,因为TimescaleDB是动态创建自己的块表的,并且您不想将它们转换为超表.

One thing that might work for your use case is to create an event trigger that executes on table creation. You'd have to check that it's in the correct schema since TimescaleDB creates its own chunk tables dynamically and you don't want to have them converted to hypertables.

有关事件触发器的更多信息,请参见以下答案: 在创建表时执行触发器

See this answer for more info on event triggers: execute a trigger when I create a table

这篇关于通过SQL炼金术创建超表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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