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 BigDecimal fail to compile #28

Open
Piszmog opened this issue Mar 7, 2025 · 0 comments · May be fixed by #29
Open

Postgres BigDecimal fail to compile #28

Piszmog opened this issue Mar 7, 2025 · 0 comments · May be fixed by #29

Comments

@Piszmog
Copy link

Piszmog commented Mar 7, 2025

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
@Piszmog Piszmog changed the title Big Decimal fail to compile Postgres BigDecimal fail to compile Mar 7, 2025
@Piszmog Piszmog linked a pull request Mar 7, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant