Description
Version
1.15.0
What happened?
PostgreSQL supports specifying BEFORE
or AFTER
when adding a value to an existing ENUM
, see docs. sqlc does not pick this up and simply appends the new values, so when the emit_all_enum_values
configuration parameter is set to true
, the order of the values returned from the All*Values()
function is not correct.
I have attached a playground URL where the necessary statements and configuration can be found. If you look at the generated implementation of AllEnumTypeValues
in db/models.go
, you can see the order is not correct.
Given the following statements:
CREATE TYPE enum_type AS ENUM ('first', 'last');
ALTER TYPE enum_type ADD VALUE 'second' AFTER 'first';
ALTER TYPE enum_type ADD VALUE 'third' BEFORE 'last';
I would expect the AllEnumTypeValues
implementation to look like this:
func AllEnumTypeValues() []EnumType {
return []EnumType{
EnumTypeFirst,
EnumTypeSecond,
EnumTypeThird,
EnumTypeLast,
}
}
but instead, it looks like this:
func AllEnumTypeValues() []EnumType {
return []EnumType{
EnumTypeFirst,
EnumTypeLast,
EnumTypeSecond,
EnumTypeThird,
}
}
Relevant log output
No response
Database schema
No response
SQL queries
No response
Configuration
No response
Playground URL
https://play.sqlc.dev/p/746548c45a823783171d5a09b59680132882e1e6786137e2e0dba3f8bcf5b1e2
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go