diff --git a/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala b/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala index fd85d27b7..817aa17e4 100644 --- a/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala +++ b/postgres/src/main/scala/zio/sql/postgresql/PostgresSqlModule.scala @@ -4,8 +4,7 @@ import java.sql.ResultSet import java.text.DecimalFormat import java.time._ import java.time.format.DateTimeFormatter -import java.util.Calendar - +import java.util.{ Calendar, UUID } import org.postgresql.util.PGInterval import zio.Chunk import zio.sql.Sql @@ -308,6 +307,7 @@ trait PostgresSqlModule extends Sql { self => val SetSeed = FunctionDef[Double, Unit](FunctionName("setseed")) val BitLength = FunctionDef[String, Int](FunctionName("bit_length")) val Pi = Expr.FunctionCall0[Double](FunctionDef[Any, Double](FunctionName("pi"))) + val GenRandomUuid = Expr.FunctionCall0[UUID](FunctionDef[Any, UUID](FunctionName("gen_random_uuid"))) } } diff --git a/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala b/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala index 8ebcf8e5c..bf988701d 100644 --- a/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala +++ b/postgres/src/test/scala/zio/sql/postgresql/FunctionDefSpec.scala @@ -177,6 +177,17 @@ object FunctionDefSpec extends PostgresRunnableSpec with DbSchema { assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) }, + test("gen_random_uuid") { + val query = select(GenRandomUuid) + + val testResult = execute(query) + + val assertion = for { + r <- testResult.runCollect + } yield assert(r.head)(!isNull) + + assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) + }, suite("format function")( test("format0") { import Expr._