Skip to content

Add configurable boolean-to-numeric conversion for ResultSet getters - #3796

Merged
davecramer merged 5 commits into
pgjdbc:masterfrom
vwassan:vw/boolean-to-numeric
Sep 15, 2025
Merged

davecramer merged 5 commits into
pgjdbc:masterfrom
vwassan:vw/boolean-to-numeric

Conversation

@vwassan

@vwassan vwassan commented Sep 12, 2025 •

Copy link
Copy Markdown
Contributor

Addresses: #367

Problem:

When calling numeric getters (getByte(), getInt(), getLong(), getShort(), getFloat(), getDouble(), getBigDecimal()) on PostgreSQL boolean columns, the driver
throws PSQLException: Bad value for type byte : f.

Solution:

Added a new connection property convertBooleanToNumeric that enables automatic conversion of PostgreSQL boolean values to numeric types:

  • 't' → 1
  • 'f' → 0
  • Works with boolean columns
  • Property cached per connection for optimal performance
  • Boolean column type detection prevents false positive conversions

Usage:

// JDBC URL
jdbc:postgresql://host:5432/db?convertBooleanToNumeric=true

// HikariCP
config.addDataSourceProperty("convertBooleanToNumeric", "true");

// Spring Boot
spring.datasource.hikari.data-source-properties.convertBooleanToNumeric=true

Backward Compatibility:

  • Default: false (maintains existing behavior)
  • getBoolean() continues working regardless of property setting
  • No changes to existing application behavior unless explicitly enabled

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Does ./gradlew styleCheck pass ?
  3. Have you added your new test classes to an existing test suite in alphabetical order?

Changes to Existing Features:

  • Does this break existing behaviour? If so please explain.
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

@vwassan
vwassan force-pushed the vw/boolean-to-numeric branch 2 times, most recently from f0cd9f9 to be922a5 Compare September 12, 2025 20:38
@vwassan
vwassan force-pushed the vw/boolean-to-numeric branch from be922a5 to 08d81ee Compare September 12, 2025 20:39
@vwassan
vwassan marked this pull request as ready for review September 12, 2025 20:51
Comment thread pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java Outdated
Comment thread pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java Outdated
@davecramer

Copy link
Copy Markdown
Member

The conversions by ResultSet getter methods says get Float, Double, and BigDecimal should support this

@vwassan
vwassan force-pushed the vw/boolean-to-numeric branch from f31fa6d to 6c62941 Compare September 14, 2025 00:40
@vwassan
vwassan requested a review from davecramer September 14, 2025 00:50
Comment thread docs/content/documentation/use.md Outdated
Comment thread pgjdbc/src/main/java/org/postgresql/PGProperty.java Outdated
@vwassan
vwassan force-pushed the vw/boolean-to-numeric branch from 6664264 to 9bbf8ee Compare September 14, 2025 14:51
@vwassan
vwassan requested a review from davecramer September 14, 2025 16:31
@vwassan

vwassan commented Sep 14, 2025

Copy link
Copy Markdown
Contributor Author

@davecramer Made the changes. One SSL-related test on CI is failing. Not sure about it.

@davecramer
davecramer merged commit a3be9d5 into pgjdbc:master Sep 15, 2025
15 of 16 checks passed
svc-squareup-copybara pushed a commit to cashapp/misk that referenced this pull request Sep 19, 2025
| Package | Type | Package file | Manager | Update | Change |
|---|---|---|---|---|---|
| [org.postgresql:postgresql](https://jdbc.postgresql.org)
([source](https://github.com/pgjdbc/pgjdbc)) | dependencies |
misk/gradle/libs.versions.toml | gradle | patch | `42.7.7` -> `42.7.8` |
|
[com.google.apis:google-api-services-cloudkms](http://nexus.sonatype.org/oss-repository-hosting.html)
([source](http://svn.sonatype.org/spice/tags/oss-parent-7)) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`v1-rev20250818-2.0.0` -> `v1-rev20250911-2.0.0` |
|
[org.assertj:assertj-core](https://assertj.github.io/doc/#assertj-core)
([source](https://github.com/assertj/assertj)) | dependencies |
misk/gradle/libs.versions.toml | gradle | patch | `3.27.4` -> `3.27.5` |
| [software.amazon.awssdk:sdk-core](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:sqs](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:s3](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:regions](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
|
[software.amazon.awssdk:dynamodb-enhanced](https://aws.amazon.com/sdkforjava)
| dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:dynamodb](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:aws-core](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:bom](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:auth](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |

---

### Release Notes

<details>
<summary>pgjdbc/pgjdbc (org.postgresql:postgresql)</summary>

###
[`v42.7.8`](https://github.com/pgjdbc/pgjdbc/blob/HEAD/CHANGELOG.md#4278-2025-09-18)

##### Added

- feat: Add configurable boolean-to-numeric conversion for ResultSet
getters [PR #&#8203;3796](pgjdbc/pgjdbc#3796)

##### Changed

- perf: remove QUERY\_ONESHOT flag when calling getMetaData [PR
#&#8203;3783](pgjdbc/pgjdbc#3783)
- perf: use `BufferedInputStream` with `FileInputStream` [PR
#&#8203;3750](pgjdbc/pgjdbc#3750)
- perf: enable server-prepared statements for DatabaseMetaData

##### Fixed

- fix: avoid NullPointerException when cancelling a query if cancel key
is not known yet
- fix: Change "PST" timezone in TimestampTest to "Pacific Standard Time"
[PR #&#8203;3774](pgjdbc/pgjdbc#3774)
- fix: traverse the current dimension to get the correct pos in
PgArray#calcRemainingDataLength [PR
#&#8203;3746](pgjdbc/pgjdbc#3746)
- fix: make sure getImportedExportedKeys returns columns in consistent
order
- fix: Add "SELF\_REFERENCING\_COL\_NAME" field to getTables'
ResultSetMetaData to fix NullPointerException [PR
#&#8203;3660](pgjdbc/pgjdbc#3660)
- fix: unable to open replication connection to servers < 12
- fix: avoid closing statement caused by driver's internal
ResultSet#close()
- fix: return empty metadata for empty catalog names as it was before
- fix: Incorrect class comparison in PGXmlFactoryFactory validation

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am
every weekday" in timezone Australia/Melbourne, Automerge - At any time
(no schedule defined).

🚦 **Automerge**: Enabled.

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

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://github.com/renovatebot/renovate/discussions) if
that's undesired.

---

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

---

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

GitOrigin-RevId: 60823b502aee625ad34c64abe2d25a884fd81fee
eizus pushed a commit to cdrxyz/misk that referenced this pull request Jul 18, 2026
| Package | Type | Package file | Manager | Update | Change |
|---|---|---|---|---|---|
| [org.postgresql:postgresql](https://jdbc.postgresql.org)
([source](https://github.com/pgjdbc/pgjdbc)) | dependencies |
misk/gradle/libs.versions.toml | gradle | patch | `42.7.7` -> `42.7.8` |
|
[com.google.apis:google-api-services-cloudkms](http://nexus.sonatype.org/oss-repository-hosting.html)
([source](http://svn.sonatype.org/spice/tags/oss-parent-7)) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`v1-rev20250818-2.0.0` -> `v1-rev20250911-2.0.0` |
|
[org.assertj:assertj-core](https://assertj.github.io/doc/#assertj-core)
([source](https://github.com/assertj/assertj)) | dependencies |
misk/gradle/libs.versions.toml | gradle | patch | `3.27.4` -> `3.27.5` |
| [software.amazon.awssdk:sdk-core](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:sqs](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:s3](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:regions](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
|
[software.amazon.awssdk:dynamodb-enhanced](https://aws.amazon.com/sdkforjava)
| dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:dynamodb](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:aws-core](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:bom](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |
| [software.amazon.awssdk:auth](https://aws.amazon.com/sdkforjava) |
dependencies | misk/gradle/libs.versions.toml | gradle | patch |
`2.33.12` -> `2.33.13` |

---

### Release Notes

<details>
<summary>pgjdbc/pgjdbc (org.postgresql:postgresql)</summary>

###
[`v42.7.8`](https://github.com/pgjdbc/pgjdbc/blob/HEAD/CHANGELOG.md#4278-2025-09-18)

##### Added

- feat: Add configurable boolean-to-numeric conversion for ResultSet
getters [PR #&#8203;3796](pgjdbc/pgjdbc#3796)

##### Changed

- perf: remove QUERY\_ONESHOT flag when calling getMetaData [PR
#&#8203;3783](pgjdbc/pgjdbc#3783)
- perf: use `BufferedInputStream` with `FileInputStream` [PR
#&#8203;3750](pgjdbc/pgjdbc#3750)
- perf: enable server-prepared statements for DatabaseMetaData

##### Fixed

- fix: avoid NullPointerException when cancelling a query if cancel key
is not known yet
- fix: Change "PST" timezone in TimestampTest to "Pacific Standard Time"
[PR #&#8203;3774](pgjdbc/pgjdbc#3774)
- fix: traverse the current dimension to get the correct pos in
PgArray#calcRemainingDataLength [PR
#&#8203;3746](pgjdbc/pgjdbc#3746)
- fix: make sure getImportedExportedKeys returns columns in consistent
order
- fix: Add "SELF\_REFERENCING\_COL\_NAME" field to getTables'
ResultSetMetaData to fix NullPointerException [PR
#&#8203;3660](pgjdbc/pgjdbc#3660)
- fix: unable to open replication connection to servers < 12
- fix: avoid closing statement caused by driver's internal
ResultSet#close()
- fix: return empty metadata for empty catalog names as it was before
- fix: Incorrect class comparison in PGXmlFactoryFactory validation

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6pm every weekday,before 2am
every weekday" in timezone Australia/Melbourne, Automerge - At any time
(no schedule defined).

🚦 **Automerge**: Enabled.

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

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://github.com/renovatebot/renovate/discussions) if
that's undesired.

---

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

---

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

GitOrigin-RevId: 60823b502aee625ad34c64abe2d25a884fd81fee
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.

2 participants