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

Postgres: uuid column throws a match error #45

Closed
Fristi opened this issue Feb 23, 2017 · 2 comments · Fixed by #46
Closed

Postgres: uuid column throws a match error #45

Fristi opened this issue Feb 23, 2017 · 2 comments · Fixed by #46
Assignees
Labels

Comments

@Fristi
Copy link

Fristi commented Feb 23, 2017

When reading a uuid column it throws a match error. This is due the reason that JDBC returns a UUID instead of the expected byte array. Hacked around it with this extension method:

/***
    * Provides extension methods to work around with issues caused by relate
    */
  private implicit class RichSqlResult(val r: SqlResult) {

    /**
      * This method exists due the reason that `SqlResult.uuid` tries to read the UUID as a byte array while
      * the JDBC driver returns a UUID causing in a match error.
      */
    def postgresUUID(column: String): UUID =
      //This is copied from extractOption (which is protected) with some modifications
      r.resultSet.getObject(column).asInstanceOf[Any] match {
        case x if (x == null || r.resultSet.wasNull()) => sys.error(s"No such column found: $column")
        case x: UUID => x
        case _ => sys.error("Not a postgres UUID")
      }
  }
@gregghz
Copy link
Collaborator

gregghz commented Feb 23, 2017

Interesting. We typically store a UUID as a byte array in the database using MySQL. This makes for an interesting problem for postgres. I'd really like to fix def uuid to support either (and any jdbc) database.

@gregghz
Copy link
Collaborator

gregghz commented Feb 23, 2017

should be fixed by #46

There's another bug in postgres for interpolating UUIDs into a query that's basically the exact same issue, but from the other direction. #47

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

Successfully merging a pull request may close this issue.

3 participants