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

Support for enums #2307

Open
joto opened this issue Feb 20, 2025 · 1 comment
Open

Support for enums #2307

joto opened this issue Feb 20, 2025 · 1 comment

Comments

@joto
Copy link
Collaborator

joto commented Feb 20, 2025

Enums are an interesting datatype in SQL. Enums can be created with CREATE TYPE in PostgreSQL. Features:

  1. Storage is relatively compact, 4 bytes only. This is less than typical text labels.
  2. Externally they behave mostly like text, making it easy to use.
  3. Enums are sorted by internal encoding, this allows "choosing" order in a sense, for instance by "importance" in a value ("motorway" before "trunk" before "primary",...) instead of text-based ordering. This is useful for map rendering.
  4. Enums can be changed with ALTER TYPE, for instance new values can be added, but they are still not as flexible as free text, of course.

Currently enums can be used with osm2pgsql by creating the enum type before osm2pgsql is run and then using sql_type = 'YOUR_ENUM_TYPE' in the table definition. After that they are used as if they were a text type.

Support in osm2pgsql could help with

  • Easier to define everything in Lua config instead of having external SQL.
  • Checking values in osm2pgsql would allow for better error messages instead of failure in the COPY command.
@pnorman
Copy link
Collaborator

pnorman commented Feb 20, 2025

In practice, you can either have a sortable ordering, or you can alter types. When you use ALTER TYPE you can't pick where in the ordering it goes. You end up having to reimport or update all rows if you want to insert in the middle of your enum.

I wrote a bunch of stuff with ClearTables that made use of ENUMs, but threw it away. The main use I find for ENUMs now is for values which might be something like -1/0/1 such as tunnel/bridge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants