timescale icon indicating copy to clipboard operation
timescale copied to clipboard

Support Ecto DSL in `enable_hypertable_compression/2`

Open davydog187 opened this issue 3 years ago • 4 comments

We have a function enable_hypertable_compression/2 which corresponds to an alter table, see the timescale docs

Currently we're only allowing you to pass the column name, but we should support the order and nulls rules as well. See below 👇🏼

ALTER TABLE <table_name> SET (timescaledb.compress, timescaledb.compress_orderby = '<column_name> [ASC | DESC] [ NULLS { FIRST | LAST } ] [, ...]',
timescaledb.compress_segmentby = '<column_name> [, ...]'
);

davydog187 avatar Aug 20 '22 13:08 davydog187

I'm trying to better understand how you want the Ecto DSL to play into this. Do you have an idea of what you sort of see the final product looking like?

enable_hypertable_compression(:prices, 
  segment_by: "currency_id", 
  order_by: [asc: :inserted_at, desc_nulls_first: :another_id]
)

doomspork avatar Aug 21 '22 14:08 doomspork

Your example is on the money. On my phone, but I believe there are some alternative ways to do that, we should support them as well

davydog187 avatar Aug 21 '22 15:08 davydog187

From the Ecto.Query.order_by/3 documentation, we should support the following examples:

from(c in City, order_by: c.name, order_by: c.population)
from(c in City, order_by: [c.name, c.population])
from(c in City, order_by: [asc: c.name, desc: c.population])

from(c in City, order_by: [:name, :population])
from(c in City, order_by: [asc: :name, desc_nulls_first: :population])

davydog187 avatar Aug 21 '22 15:08 davydog187

Adding as a note here that this issue should also address the SQL injection issues mentioned in https://github.com/bitfo/timescale/issues/11

akoutmos avatar Aug 29 '22 15:08 akoutmos