Skip to content

Cast BigInt values to text in JSON aggregation for MySQL/Cockroach#5752

Merged
aqrln merged 5 commits intoprisma:mainfrom
polaz:fix/#1-bigint-json-cast
Jan 30, 2026
Merged

Cast BigInt values to text in JSON aggregation for MySQL/Cockroach#5752
aqrln merged 5 commits intoprisma:mainfrom
polaz:fix/#1-bigint-json-cast

Conversation

@polaz
Copy link
Contributor

@polaz polaz commented Jan 29, 2026

Closes #5751.

Summary

  • Cast MySQL BigInt/UnsignedBigInt values to CHAR in JSON_OBJECT to preserve precision in JS JSON parsing.
  • Extend Postgres visitor to also cast Cockroach INT8/Int8 to text in JSONB_BUILD_OBJECT.
  • Add visitor tests for both cases.

polaz added 2 commits January 20, 2026 15:25
Cast BigInt columns to ::text inside JSONB_BUILD_OBJECT to preserve
precision when parsed by JavaScript. JavaScript's JSON.parse loses
precision for integers larger than 2^53-1 (Number.MAX_SAFE_INTEGER).

This is analogous to the existing MONEY -> ::numeric cast.

Closes prisma#1
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses BigInt precision loss in JSON aggregation for MySQL and CockroachDB by casting BigInt values to text/string in JSON object builders. The motivation is that JavaScript's JSON.parse loses precision for integers larger than 2^53-1.

Changes:

  • Extended the Postgres visitor to cast Int8/INT8 (CockroachDB native types) to text in JSONB_BUILD_OBJECT
  • Added MySQL visitor logic to convert BigInt/UnsignedBigInt to CHAR in JSON_OBJECT
  • Added test cases for BigInt and Int8 in Postgres visitor
  • Added test case for BigInt in MySQL visitor

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
quaint/src/visitor/postgres.rs Added pattern matching to cast BigInt/Int8/INT8 columns to text in JSON builds, plus tests for bigint and int8
quaint/src/visitor/mysql.rs Added pattern matching to convert BigInt/UnsignedBigInt to CHAR in JSON builds, plus test for bigint, and added ast import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 29, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing polaz:fix/#1-bigint-json-cast (eaaff35) with main (541b063)1

Summary

✅ 11 untouched benchmarks
⏩ 11 skipped benchmarks2

Footnotes

  1. No successful run was found on main (f3eee96) during the generation of this report, so 541b063 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 11 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@aqrln aqrln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, also tested them to confirm this fixes the issue. Thank you!

@aqrln aqrln modified the milestones: 7.3.0, 7.4.0 Jan 30, 2026
@aqrln aqrln merged commit dd122f8 into prisma:main Jan 30, 2026
102 of 103 checks passed
@polaz polaz deleted the fix/#1-bigint-json-cast branch January 31, 2026 11:44
t-i-0414 pushed a commit to t-i-0414/music-practice-tracker that referenced this pull request Feb 15, 2026
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [@prisma/client](https://www.prisma.io)
([source](https://redirect.github.com/prisma/prisma/tree/HEAD/packages/client))
| [`7.3.0` →
`7.4.0`](https://renovatebot.com/diffs/npm/@prisma%2fclient/7.3.0/7.4.0)
|
![age](https://developer.mend.io/api/mc/badges/age/npm/@prisma%2fclient/7.4.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@prisma%2fclient/7.3.0/7.4.0?slim=true)
|
| [prisma](https://www.prisma.io)
([source](https://redirect.github.com/prisma/prisma/tree/HEAD/packages/cli))
| [`7.3.0` →
`7.4.0`](https://renovatebot.com/diffs/npm/prisma/7.3.0/7.4.0) |
![age](https://developer.mend.io/api/mc/badges/age/npm/prisma/7.4.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/prisma/7.3.0/7.4.0?slim=true)
|

---

### Release Notes

<details>
<summary>prisma/prisma (@&#8203;prisma/client)</summary>

###
[`v7.4.0`](https://redirect.github.com/prisma/prisma/releases/tag/7.4.0)

[Compare
Source](https://redirect.github.com/prisma/prisma/compare/7.3.0...7.4.0)

Today, we are excited to share the `7.4.0` stable release 🎉

**🌟 Star this repo for notifications about new releases, bug fixes &
features — or [follow us on X](https://pris.ly/x)!**

##### Highlights

##### ORM

##### Caching in Prisma Client

Today’s release is a big one, as we introduce a new caching layer into
Prisma ORM. But why the need for a caching layer?

In Prisma 7, the query compiler runs as a WebAssembly module directly on
the JavaScript main thread. While this simplified the architecture by
eliminating the separate engine process, it introduced a trade-off:
every query now synchronously blocks the event loop during compilation.

For individual queries, compilation takes between 0.1ms and 1ms, which
is barely noticeable in isolation. But under high concurrency this
overhead adds up and creates event loop contention that affects overall
application throughput.

For instance, say we have a query that is run over and over, but is a
similar shape:

```tsx
// These two queries have the same shape:
const alice = await prisma.user.findUnique({ where: { email: 'alice@prisma.io' } })
const bob = await prisma.user.findUnique({ where: { email: 'bob@prisma.io' } })
```

Prior to v7.4.0, this would be reevaluated ever time the query is run.
Now, Prisma Client will extract the user-provided values and replaces
them with typed placeholders, producing a normalized query shape:

```
prisma.user.findUnique({ where: { email: %1 } })   // cache key
                                         ↑
                              %1 = 'alice@prisma.io'  (or 'bob@prisma.io')
```

This normalized shape is used as a cache key. On the first call, the
query is compiled as usual and the resulting plan is stored in an LRU
cache. On every subsequent call with the same query shape, regardless of
the actual values, the cached plan is reused instantly without invoking
the compiler.

We have more details on the impact of this change and some deep dives
into Prisma architecture in an upcoming blog post!

##### Partial Indexes (Filtered Indexes) Support

We're excited to announce **Partial Indexes** support in Prisma! This
powerful community-contributed feature allows you to create indexes that
only include rows matching specific conditions, significantly reducing
index size and improving query performance.

Partial indexes are available behind the `partialIndexes` preview
feature for PostgreSQL, SQLite, SQL Server, and CockroachDB, with full
migration and introspection support.

**Basic usage**

Enable the preview feature in your schema:

```groovy
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["partialIndexes"]
}
```

**Raw SQL syntax**

For maximum flexibility, use the `raw()` function with database-specific
predicates:

```groovy
model User {
  id       Int     @&#8203;id
  email    String
  status   String

  @&#8203;@&#8203;unique([email], where: raw("status = 'active'"))
  @&#8203;@&#8203;index([email], where: raw("deletedAt IS NULL"))
}
```

**Type-safe object syntax**

For better type safety, use the object literal syntax for simple
conditions:

```groovy
model Post {
  id        Int      @&#8203;id
  title     String
  published Boolean

  @&#8203;@&#8203;index([title], where: { published: true })
  @&#8203;@&#8203;unique([title], where: { published: { not: false } })
}
```

##### Bug Fixes

Most of these fixes are **community contributions** - thank you to our
amazing contributors!

-
[**prisma/prisma-engines#5767**](https://redirect.github.com/prisma/prisma-engines/pull/5767):
Fixed an issue with PostgreSQL migration scripts that prevented usage of
`CREATE INDEX CONCURRENTLY` in migrations
-
[**prisma/prisma-engines#5752**](https://redirect.github.com/prisma/prisma-engines/pull/5752):
Fixed BigInt precision loss in JSON aggregation for MySQL and
CockroachDB by casting BigInt values to text (from community member
[polaz](https://redirect.github.com/polaz))
-
[**prisma/prisma-engines#5750**](https://redirect.github.com/prisma/prisma-engines/pull/5750):
Fixed connection failures with non-ASCII database names by properly
URL-decoding database names in connection strings
-
[**#&#8203;29155**](https://redirect.github.com/prisma/prisma/pull/29155):
Fixed silent transaction commit errors in PlanetScale adapter by
ensuring COMMIT failures are properly propagated
-
[**#&#8203;29141**](https://redirect.github.com/prisma/prisma/pull/29141):
Resolved race condition errors (EREQINPROG) in SQL Server adapter by
serializing commit/rollback operations using mutex synchronization
-
[**#&#8203;29158**](https://redirect.github.com/prisma/prisma/pull/29158):
Fixed MSSQL connection string parsing to properly handle curly brace
escaping for passwords containing special characters

##### Open roles at Prisma

Interested in joining Prisma? We’re growing and have several exciting
opportunities across the company for developers who are passionate about
building with Prisma. Explore our open positions on our [Careers
page](https://www.prisma.io/careers#current) and find the role that’s
right for you.

##### Enterprise support

Thousands of teams use Prisma and many of them already tap into our
Enterprise & Agency Support Program for hands-on help with everything
from schema integrations and performance tuning to security and
compliance.

With this program you also get priority issue triage and bug fixes,
expert scalability advice, and custom training so that your
Prisma-powered apps stay rock-solid at any scale. Learn more or
join: <https://prisma.io/enterprise>.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Never, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://redirect.github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45OS4wIiwidXBkYXRlZEluVmVyIjoiNDIuOTkuMCIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19-->

Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
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 this pull request may close these issues.

Fix BigInt precision in JSON aggregation for MySQL and CockroachDB

2 participants

Comments