Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: support ENUM types #24873

Closed
Tracked by #33441
jseldess opened this issue Apr 17, 2018 · 17 comments
Closed
Tracked by #33441

sql: support ENUM types #24873

jseldess opened this issue Apr 17, 2018 · 17 comments
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) X-anchored-telemetry The issue number is anchored by telemetry references.

Comments

@jseldess
Copy link
Contributor

jseldess commented Apr 17, 2018

Special case of #25123.

Feature request: Postgres supports ENUM types for defining columns that can contain only a given set of values. CockroachDB should, too.

https://www.postgresql.org/docs/10/static/datatype-enum.html

Special note:

Whenever a user-defined type is created (with CREATE TYPE), PostgreSQL automatically creates an associated array type, whose name consists of the element type's name prepended with an underscore, and truncated if necessary to keep it less than NAMEDATALEN bytes long. (If the name so generated collides with an existing type name, the process is repeated until a non-colliding name is found.) This implicitly-created array type is variable length and uses the built-in input and output functions array_in and array_out. The array type tracks any changes in its element type's owner or schema, and is dropped if the element type is.

@danhhz
Copy link
Contributor

danhhz commented Apr 17, 2018

This would also be an important building block in query planning for some instances of partitioned tables. Some background on this at https://github.com/cockroachdb/cockroach/blob/2f2cb3af3df0bebf01bd2f0bb9c8329ad44229df/docs/RFCS/20170921_sql_partitioning.md#query-planning-changes

@knz
Copy link
Contributor

knz commented Apr 17, 2018

cc @awoods187 for prioritization

@knz knz added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-pgcompat Semantic compatibility with PostgreSQL labels Apr 17, 2018
@knz knz added C-wishlist A wishlist feature. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) and removed C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) C-wishlist A wishlist feature. labels May 2, 2018
@awoods187 awoods187 changed the title Support for ENUM and SET types Support for ENUM type Jul 11, 2018
@awoods187
Copy link
Contributor

Split SET into a new issue #27415

@knz knz changed the title Support for ENUM type sql: support ENUM types Jul 20, 2018
@knz knz added the X-anchored-telemetry The issue number is anchored by telemetry references. label Nov 22, 2018
@knz knz removed their assignment Jan 3, 2019
@ghost
Copy link

ghost commented Jan 21, 2019

In which release can we expect this feature?

@knz
Copy link
Contributor

knz commented Jan 21, 2019

It's not planned yet.

@orefalo
Copy link

orefalo commented Feb 2, 2019

No Enum? that's a show stopper for me.

don't understand what makes this simple constraint so difficult to implement.

@knz
Copy link
Contributor

knz commented Feb 2, 2019 via email

@orefalo
Copy link

orefalo commented Feb 2, 2019

Thank you. But then.. custom types are also missing, and stored procedure also seem to have their issues.
Hum.. It's not going to be that easy to get Graphile working against cockroach.

;-)

@allenvino1
Copy link

Very excited for this 👍

@Y0ngg4n
Copy link

Y0ngg4n commented Mar 20, 2020

Any updates on this Feature?

@jordanlewis
Copy link
Member

@Y0ngg4n, we're likely to work on it for our 20.2 release, which will be in late 2020. Unfortunately we didn't get to it for 20.1, which is going to be released in the next month or so.

@rohany
Copy link
Contributor

rohany commented Mar 31, 2020

Hi all -- we're looking into implementing this and are wondering how often the postgres supported behavior of

alter type t add value v [BEFORE | AFTER] v2

is used. This syntax adds a new value to an existing enum but affects how it is ordered against other elements in the enum, rather than just ordering it larger than all existing elements.

Thanks!

@hazcod
Copy link
Contributor

hazcod commented Apr 1, 2020

@rohany I never used ordering within an enum to be honest.

@lukaseder
Copy link

@rohany A customer of ours is using this feature in newer versions of PostgreSQL. They wrote their own database change management utility that can logically reorder columns in tables as well to make sure every schema on every installation and environment always looks the same.

The benefit is when development uses feature branching, and two branches add columns (or enumeration values) in different order, depending on how they're merged and linearised, there are no unwanted and untested side effects due to ordering. I see this as a nice feature from a QA perspective.

Yes, it's possible to code all logic to be resilient to ordering changes, but that's a lot of effort, which can be avoided.

@karlseguin
Copy link

Internally, will they be stored as integers, thus yielding a performance win? Or is the initially goal just to enforce the constraint?

@rohany
Copy link
Contributor

rohany commented Jun 24, 2020

They won't be integers internally, but we have a separate representation for them that will use only a single byte in most cases! You can read about it here https://github.com/cockroachdb/cockroach/blob/master/docs/RFCS/20200331_enums.md#physical-layout.

@rohany
Copy link
Contributor

rohany commented Aug 5, 2020

Marking this as done!

@rohany rohany closed this as completed Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) X-anchored-telemetry The issue number is anchored by telemetry references.
Projects
None yet
Development

No branches or pull requests