Skip to content

getPrecision() for Varchar returns 0 #340

Closed

Description

@ahmedanadwc

For all VARCHAR types: Regardless of whether you define a length for the VARCHAR column, the getPrecision() method will always return a hardcoded value of 0.

Within the DuckDBResultSetMetaData.java file, the getPrecision(int column) method in the DuckDB JDBC driver does not return the defined length of a VARCHAR variable. Instead, for VARCHAR types, the getPrecision() method returns a hardcoded value of 0.
This means that even if you define a VARCHAR with a specific length in your DuckDB table, the JDBC driver will not report this length to the client application.

When compared to PostgreSQL implementation, the PostgreSQL JDBC driver provides a more nuanced and informative implementation of getPrecision() compared to the DuckDB driver. Here's how it behaves:

  • For VARCHAR(n): When you define a column as VARCHAR with a specific length (e.g., VARCHAR(100)), the getPrecision() method will return that defined length (100 in this case).

  • For VARCHAR (without a length) and TEXT: PostgreSQL treats VARCHAR without a length specifier as equivalent to the TEXT data type, both of which can store strings of virtually unlimited length. In this scenario, the PostgreSQL JDBC driver will typically return a very large value, often Integer.MAX_VALUE (2,147,483,647), to signify that there is no predefined limit.

Activity

  1. staticlibs commented on Sep 8, 2025

    @staticlibs
    Member

    Hi, thanks for the report!

    Though Postgres has more sophisticated handling for precision for different types, like in your example it supports string both with and without length. DuckDB does not support length (as a type modifier) for VARCHAR (modifier is ignored when present), so the JDBC driver returns 0 consistently for all types where precision is not defined, and VARCHAR is one of them.

    If you know some piece of software (with a JDBC client) that breaks because of this behaviour - please let us know. We can add special casing for compatibility, but by default we'd rather return 0 consistently.

  2. ahmedanadwc commented on Sep 8, 2025

    @ahmedanadwc
    Author

    Hi,
    Thanks for responding to this issue.
    I used SAS Software with their access to JDBC. When trying to access a table via DuckDB, I can get over all the numeric variables without any issues, but all my Varchar/Char/String variables get a length of 0! basically they end-up as empty fields!!
    When I investigated this, it turned out

    • SAS uses DuckDBResultSetMetaData.java to identify column types and lengths, while other Java Clients, such as DBeaver seems to use DuckDBResultSet.java, according to Google Gemini CLI.

    And that's when I went ahead and had Gemini investigate the Postgres JDBC driver for comparison.

  3. added a commit that references this issue on Sep 9, 2025
    ed694f5
  4. staticlibs commented on Sep 9, 2025

    @staticlibs
    Member

    @ahmedanadwc

    Thanks for the details! I've filed #367 to make the returned values of getPrecision() call closer to ones returned by Postgres.

  5. ahmedanadwc commented on Sep 9, 2025

    @ahmedanadwc
    Author

    That would be great, much appreciated

  6. added 3 commits that reference this issue on Sep 12, 2025
    4ccafc4
    431083f
    fb4a4a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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