shuttle-hq / synth

The Declarative Data Generator
https://www.getsynth.com/
Apache License 2.0
1.39k stars 109 forks source link

Support for importing PostgreSQL schema containing range and multirange types #328

Open deinspanjer opened 2 years ago

deinspanjer commented 2 years ago

Required Functionality Several types in pg support being used in a range type field. https://www.postgresql.org/docs/current/rangetypes.html

It would be great to get range support as described in #305, but there is an additional step beyond that now. Multiranges are effectively a builtin type that supports an array of range entries.

Proposed Solution Both range and multirange types can be coerced to and from strings, this might be the easiest way to get initial support for them into Synth.

Ranges can be inclusive or exclusive on either end. This is indicated by using a square bracket [ or ] for inclusive or a round bracket ( or ) for exclusive. Hence, (0,5] means an integer greater than 0 and less than or equal to five.

An intrange could be expressed as any of these strings: (0,5] [1,3] ()

An int multirange wraps multiple ranges in curly brackets: {(0,5],[7,8]}

The same format follows for each of the range and multirange supported data types.

Use case I have a pg schema with several tstzmultirange columns that support temporal tracking (i.e. At what times was this record valid or enabled or a member.) I am okay with initial support of just giving a static default for the fields in the synth schema, but for now, I can't build any of the schema via import.