Skip to content

Commit 3913d3a

Browse files
authored
Merge pull request #1088 from typelevel/backport/1086
Handle Postgres oids greater than Int.MaxValue
2 parents 65e2794 + 24d482c commit 3913d3a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/core/shared/src/main/scala/util/Typer.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ object Typer {
177177
case class TypeInfo(oid: Int, name: String, arrayTypeOid: Option[Int], relOid: Option[Int])
178178

179179
implicit class ProtocolOps[F[_]: Functor](p: Protocol[F]) {
180-
val oid: Codec[Int] = Codec.simple(_.toString, _.toInt.asRight, Type.oid)
180+
//Note Postgres defines oids as *unsigned* Ints https://www.postgresql.org/docs/current/datatype-oid.html
181+
//Since Scala currently lacks a built-in unsigned Int type, if the oid exceeds `Int.MaxValue`
182+
//it will be converted to/from a negative Int by this Codec (only observed in CockroachDB)
183+
val oid: Codec[Int] = Codec.simple(java.lang.Integer.toUnsignedLong(_).toString, _.toLong.toInt.asRight, Type.oid)
181184

182185
val typeInfoMap: F[Map[Int, TypeInfo]] = {
183186

0 commit comments

Comments
 (0)