Skip to content

getPrecision() for Varchar returns 0 #340

@ahmedanadwc

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.

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