Live data from Hacker News

Multiranges in Postgres

cybertec-postgresql.com

31–34 of 34 posts

Re: Multiranges in Postgres

#31
post #26

Earlier quoted context omitted.

However, multirange GiST is implemented by merging all ranges into a single range (ignoring any gaps), which makes it less useful in many cases. src: https://github.com/postgres/postgres/blob/f14aad5169baa5e2ac...

Right, but it just means the index is not used as the final source of truth and the DB has to run an exact check on the smaller subset of rows returned. You won't get incorrect queries, but depending on the workload it may not be a useful index for improving query speed.

Yep. In our case we were using it for scheduling purposes and "Who is free on thursday at 2pm?" and we got very little narrowing because most people are available at least some time in the morning and some time in the evening.

We've loosely landed at just materializing the dataset into another table by calling `unnest` in a trigger and then using an index on that table.

Re: Multiranges in Postgres

#32

Earlier quoted context omitted.

SQL Server/MSSQL is just yet another (relatively poor) implementation of the SQL standard with a very presumptuous name.

Would you mind sharing concrete examples of SQL Server deviating from the standard ?

One thing that comes to mind is that you have to quote table and column names that don't follow the identifier pattern [like so] instead of "like so". Though I haven't kept up to date on this, maybe it can now also support SQL standard compliant table/column name quoting. Even MySQL can now do that (with a config option, at least).

That's only a tiny thing, though. I'm sure there is more. I don't use Microsoft SQL Server. Quite happy with PostgreSQL (and SQLite for tiny in file things).

Re: Multiranges in Postgres

#33
post #30

Is there a name for the ` <@ ` operator? Been calling it the tornado operator but I haven't found anything indicating an "official" name.

An older version of the documentation calls them the array containment operators:

> The array containment operators () [...]

https://www.postgresql.org/docs/9.6/functions-array.html

Re: Multiranges in Postgres

#34
post #2

Wow, I was just trying to solve the problem of merging overlapping periods in ruby. Life would be so much easier if the database did it for me!

If you want to do this with a data structure instead of a database then discrete interval encoding trees solve this problem well. https://xlinux.nist.gov/dads/HTML/discretintrv.html
Post reply on HN