Skip to content

CallableStatement#getUpdateCount() seems wrong for stored procedures #3234

@beikov

Description

@beikov

Describe the issue
The return of CallableStatement#getUpdateCount() is 0 when calling a PostgreSQL stored procedure, which seems wrong since lots of other databases/drivers return -1.

Driver Version?
42.6.2
Java Version?
17
OS Version?
Windows/Linux
PostgreSQL Version?
16.1-1
To Reproduce
See code

Expected behaviour
Return an update count of -1.

Logs

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class TestNullsFirst {
    public static void main(String []args) throws Exception {
        String url = "jdbc:postgresql://localhost:5432/test";

        Properties props = new Properties();
        props.setProperty("user", "test");
        props.setProperty("password", "test");
        try ( Connection conn = DriverManager.getConnection(url, props) ){
            try ( Statement statement = conn.prepareStatement() ) {
                statement.execute( "create table emps (id int not null primary key, name text)");
                statement.execute( "create procedure DeleteAllEmp() language 'plpgsql' as ' begin delete from emps where name is null; END ;'");
            }
            try ( CallableStatement statement = conn.prepareCall("{call DeleteAllEmp()}") ) {
                statement.execute();
                System.out.println( "UpdateCount: " + statement.getUpdateCount() );
            }
        }
    }
}

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