Menu

1 / 3

TimescaleDB Foreign Keys and Hypertables: Which Directions Work, and Which One Breaks Retention

DEV Community: sql·Son Tran·10 days ago
#PxhX9K8N
#devtosql#devto#dev#table#hypertable
Long article (1720 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.

TL;DR: A hypertable can reference a plain table, a plain table can reference a hypertable, and a hypertable cannot reference a hypertable, itself included. The middle case is the trap: the key is accepted, and then drop_chunks and the retention policy refuse to drop chunks, even when no row points into them. Point the key at the plain entity table, such as devices , and keep the reading time as an ordinary column.

A TimescaleDB hypertable can reference a plain table, and a plain table can reference a hypertable, but only the first direction works with a retention policy.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.