Received resultset tuples, but no field structure for them

From: Seth Duda <sethduda(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Received resultset tuples, but no field structure for them
Date: 2017-12-18 15:31:57
Message-ID: CAMX=jFymKNLZ5Ld0hs3b=5kB5J=e8ejxr45rWaPdzhnWP0h-Aw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The JDBC driver is throwing an "IllegalStateException: Received resultset
tuples, but no field structure for them" exception in the following
scenario:

Execute the same query 5 times and cause an exception to be thrown the 5th
time (e.g. value too long error). Prepare Threshold must be set to 5. When
you execute the same query the 6th time, you'll receive an
IllegalStateException.

Below is an example of how to reproduce the error. Tested using JDBC driver
v42.1.4 and PostgreSQL 9.4.7.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import org.postgresql.util.PSQLException;

public class IllegalStateExceptionTest {

public static void main(String[] args) throws Exception {

/*
* CREATE TABLE test ( val varchar(10) )
*/

Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/XXX?user=XXXX&password=XXXX";
Connection conn = DriverManager.getConnection(url);
conn.setAutoCommit(false);
PreparedStatement ps = conn.prepareStatement("insert into test (val) values
(?)", new String[] { "val" });
ps.setString(1, "TEST");

System.out.println("Execution #1 (OK)");
ps.executeUpdate();
conn.rollback();
System.out.println("Execution #2 (OK)");
ps.executeUpdate();
conn.rollback();
System.out.println("Execution #3 (OK)");
ps.executeUpdate();
conn.rollback();
System.out.println("Execution #4 (OK)");
ps.executeUpdate();
conn.rollback();
System.out.println("Execution #5 (OK)");
try {
// Send a value that's too long on the 5th request
ps.setString(1, "TESTTESTTEST");
ps.executeUpdate();
} catch (PSQLException e) {
// Expected error: org.postgresql.util.PSQLException: ERROR: value
// too long for type character varying(10)
conn.rollback();
}
// Send a valid value on the 6th request
ps.setString(1, "TEST");
System.out.println("Execution #6 (java.lang.IllegalStateException: Received
resultset tuples, but no field structure for them)");
ps.executeUpdate();
conn.rollback();
}

}

Here is the stack trace of the error:

Exception in thread "main" java.lang.IllegalStateException: Received
resultset tuples, but no field structure for them
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2172)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:302)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:440)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:358)
at
org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
at
org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
at IllegalStateExceptionTest.main(IllegalStateExceptionTest.java:47)

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2017-12-18 15:36:18 BUG #14983: ERROR: duplicate key value violates unique constraint "oid_tbl_oid_key"
Previous Message Сергей А. Фролов 2017-12-18 15:28:47 Re: BUG #14940: Duplicated records inspite of primary key and unique constraint