Skip to content

enum types don't work with Repo methods by default #139

@j-mie6

Description

@j-mie6

I have an enum with a derived DbCodec. However, when using it in something like Repo.insert, you will end up getting the following (on Postgres, at least):

com.augustnagro.magnum.SqlException: Error executing query:
INSERT INTO my_table (enum_name) VALUES (?)
With message:
org.postgresql.util.PSQLException: ERROR: column "enum_name" is of type my_enum but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 79

The fix, is that when you use an enum-based field in the SQL, you need to write enum_name::text when using queries on it, and for insertions, the ? should be ?::my_enum. I guess the Repo generation needs to be aware of splicing in enum values?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions