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

ST_AsWKB() returns String #469

Open
edigonzales opened this issue Dec 22, 2024 · 2 comments
Open

ST_AsWKB() returns String #469

edigonzales opened this issue Dec 22, 2024 · 2 comments

Comments

@edigonzales
Copy link

Not sure if it's (also) related with the jdbc driver but when requesting the geometry type as wkb blob with ST_AsWKB() it seems that a string is returned.

Observations:
A select query with ST_AsWKB() shows the geometry as readable output in the duckdb cli and dbeaver, e.g. "MULTIPOLYGON((...))". I would expect to see some binary representation.
Using jdbc to retrieve the result from the same query in Java. The result object seems to be also a string.

Java code:

public class JdbcDuck {

    public static void main(String... args) throws SQLException {

        String dburl = "jdbc:duckdb:mytest.duckdb";

        // Database connection parameters
        String url = "jdbc:duckdb:mytest.duckdb"; 
        String user = null;        
        String password = null;     

        // SQL statements
        String loadSpatialSQL = "LOAD SPATIAL"; 
        String selectSQL = "SELECT ST_AsWKB(mpoly) FROM afu_abbaustellen_pub_v1.abbaustelle_abbaustelle";

        try (Connection connection = DriverManager.getConnection(url, user, password);
             Statement statement = connection.createStatement()) {

            // Execute LOAD SPATIAL
            out.println("Executing: " + loadSpatialSQL);
            statement.execute(loadSpatialSQL);
            out.println("LOAD SPATIAL executed successfully.");

            // Execute SELECT query
            out.println("Executing: " + selectSQL);
            ResultSet resultSet = statement.executeQuery(selectSQL);

            // Process the result set
            while (resultSet.next()) {
                int columnCount = resultSet.getMetaData().getColumnCount();
                for (int i = 1; i <= columnCount; i++) {
                    Object obj = resultSet.getObject(i);
                    System.out.println(obj.getClass());
                }
                out.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

mytest.duckdb.zip

@Maxxen
Copy link
Member

Maxxen commented Dec 22, 2024

Hello! This is currently expected, because "WKB_BLOB" is a "custom type" it gets automatically cast to string in clients that dont know how to handle it natively. Internally, its still binary though. You can cast the result to blob explicitly to get the binary representation.

@edigonzales
Copy link
Author

Thanks. Casting to a blob explicitly helped.

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

No branches or pull requests

2 participants