Skip to content

Postgres BigDecimal fail to compile #28

Open
@Piszmog

Description

@Piszmog

Environment

  • Engine: postgresql
  • Plugin: sqlc-gen-kotlin_1.2.0.wasm / 22b437ecaea66417bbd3b958339d9868ba89368ce542c936c37305acf373104b
  • sqlc version: 1.28.0

Issue

Setup

I have the following migration.

CREATE TABLE counts (
    slug text PRIMARY KEY,
    count numeric NOT NULL,
    increments numeric
);

I have the following queries.

-- name: ListCounts :many
SELECT *
FROM counts;

-- name: CreateCounts :one
INSERT INTO counts (
    slug,
    count,
    increments
) VALUES (
$1,
$2,
$3
) RETURNING *;

Generated Code

The generated models

data class Count (
  val slug: String,
  val count: java.math.BigDecimal,
  val increments: java.math.BigDecimal?
)

Generated queries

  @Throws(SQLException::class)
  override fun createCounts(
      slug: String,
      count: java.math.BigDecimal,
      increments: java.math.BigDecimal?): Count? {
    return conn.prepareStatement(createCounts).use { stmt ->
      stmt.setString(1, slug)
          stmt.setjava.math.BigDecimal(2, count)
          stmt.setjava.math.BigDecimal(3, increments)

      val results = stmt.executeQuery()
      if (!results.next()) {
        return null
      }
      val ret = Count(
                results.getString(1),
                results.getjava.math.BigDecimal(2),
                results.getjava.math.BigDecimal(3)
            )
      if (results.next()) {
          throw SQLException("expected one row in result set, but got many")
      }
      ret
    }
  }

Errors

  • There is no stmt.setjava.math.BigDecimal
  • There is no results.getjava.math.BigDecimal

Proposed changes

  • Update the postgres type of numeric to be just BigDecimal and import java.math.BigDecimal when used

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions