Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qY6oz-000ny1-KQ for pgsql-general@arkaria.postgresql.org; Mon, 21 Aug 2023 15:28:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qY6oy-007YwC-Ee for pgsql-general@arkaria.postgresql.org; Mon, 21 Aug 2023 15:28:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qY6oa-007YsQ-UE for pgsql-general@lists.postgresql.org; Mon, 21 Aug 2023 15:27:36 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qY6oX-000Bx7-ND for pgsql-general@lists.postgresql.org; Mon, 21 Aug 2023 15:27:35 +0000 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-500772c7889so659104e87.0 for ; Mon, 21 Aug 2023 08:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iisgubbio.edu.it; s=google; t=1692631651; x=1693236451; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=euxFCJ/VLZXxBi9crWFIYoKuyl2W08iuDDTGF0pIK04=; b=OAnshkX1zRtvysHZP5kiuBlW3zNT6vhbtC6HqYozwgIHvQKjc+FBwZOde54uMceM2c VfUElzZ/cZyBypkXtzuJCRie7M8P+p4OR1F/87L3oVVGFWIPmTieU8bCgxfUStHVgfbR BJBJ5f0SOW5IAfP6ulWpBdbt0RjpjkKjEINWhCqhyiToV0qM7asY6Rek2IUhhzZLB2v8 Uw0OCUx8ASW+Ie0JQ7ymYCKhnd3knGUWN65AlV0d8gvSK5dVR8puWJMzFxBh8g8FlSoN iHlAk/Ru2hnNtqLV9FrVMP44NJda+q6h51hiLzaEYKXZ7WFHhj3WTiRPRiKyqRW3tSe2 jOhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692631651; x=1693236451; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=euxFCJ/VLZXxBi9crWFIYoKuyl2W08iuDDTGF0pIK04=; b=CdkUonZT0BKJ9wxD5rA+qslmFhle28q4b7jERbGfDmbRNpiENq5QtRxsWpF45lP0ON bcGZVCyH05nJRdufsoHIH/6WhKiBRi+yValIaTIphO8oI0oaHepSrwO8ZtihsXmDrH/z Q1DmI3m4nNYbA+/qAUWv2H23FIo6OD80KJNm0RXATGy9Li/mFUanDk2BbBKT5OomYcDT qzVzSDLTg0LP4459DOXvanlwgIAB/lwmEAksZ222f70CI4Wwp8KjeVNZ0ueoDtNmodFC aCnGAgiH5K3uDJblSpBhlz7g+97tcHTxz8bKjA6PiJ/TOuAP6KSk2T7WpCi1EFpbjwC9 QVYA== X-Gm-Message-State: AOJu0YykFwS2NsNxSBoM27Q/eD4s3F/mtcGMYxI08FM9ckvs+okec6rv tbgw1CUZY9t+eQDDZix0oeBjU8TIRZWF6tUoEdo= X-Google-Smtp-Source: AGHT+IGU5blJ2PeLEAAz5r/ZWDiWGhIW/CojEIYAf3PO40dO3WGWaHStLznGpS882lKO1SQU87ttFQ== X-Received: by 2002:ac2:48b4:0:b0:4fd:cab4:7d13 with SMTP id u20-20020ac248b4000000b004fdcab47d13mr4225126lfg.0.1692631651139; Mon, 21 Aug 2023 08:27:31 -0700 (PDT) Received: from smtpclient.apple (host-79-47-189-141.retail.telecomitalia.it. [79.47.189.141]) by smtp.gmail.com with ESMTPSA id e8-20020aa7d7c8000000b005231e1780aasm6109512eds.91.2023.08.21.08.27.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Aug 2023 08:27:30 -0700 (PDT) From: Edoardo Panfili X-Google-Original-From: Edoardo Panfili Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) Subject: The same prepared query yield "-1" the first six times and then "-1.0" Message-Id: <5C40B9CC-40E4-4AC5-95A1-E5A521C282EF@gmail.com> Date: Mon, 21 Aug 2023 17:27:20 +0200 To: pgsql-general@lists.postgresql.org X-Mailer: Apple Mail (2.3731.600.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, I am using postgresql version: 15.3 (Debian 15.3-0+deb12u1) org.postgresql.postgresql JDBC driver version: 42.6.0 via Java 17.0.7 I discovered an unattended (for me) situation: when I execute=20 10 times the same prepared query the result is not always the same. I wrote a little test case to show this. this is the db that I am using: CREATE TABLE number( name character varying(30) NOT NULL, dim1 real DEFAULT '-1' NOT NULL ); insert into number (name) VALUES('first'); and the test program: static final String DB_URL =3D = "jdbc:postgresql://192.168.64.7:5432/testdb"; static final String USER =3D "user"; static final String PASS =3D "password"; public static void main(String[] args) throws Exception { Connection conn =3D DriverManager.getConnection(DB_URL, USER, PASS); for(int i=3D0; i<10; i++) { try( PreparedStatement istruzioneCelle =3D conn.prepareStatement( "SELECT dim1 FROM number WHERE name=3D'first'") ) { ResultSet rs =3D istruzioneCelle.executeQuery(); rs.next(); System.out.print("p: "+rs.getString("dim1")+"\n=E2=80=9D); } catch (SQLException e) { e.printStackTrace(); }=20 } conn.close(); } The attended result was a sequence of ten equal values but this is the = actual result: p: -1 p: -1 p: -1 p: -1 p: -1 p: -1.0 p: -1.0 p: -1.0 p: -1.0 p: -1.0 All works fine if I open and close the connection after every single = query but in production I am using pooled connections. This is what I can read in postgresql logs (it seems that after 4 = queries the statement becomes named and the result changes after the second call = to the named query): 2023-08-21 11:51:50.633 CEST [1511] user@testdb LOG: execute : = SET extra_float_digits =3D 3 2023-08-21 11:51:50.634 CEST [1511] user@testdb LOG: execute : = SET application_name =3D 'PostgreSQL JDBC Driver' 2023-08-21 11:51:50.644 CEST [1511] user@testdb LOG: execute : = SELECT dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.648 CEST [1511] user@testdb LOG: execute : = SELECT dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.649 CEST [1511] user@testdb LOG: execute : = SELECT dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.650 CEST [1511] user@testdb LOG: execute : = SELECT dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.651 CEST [1511] user@testdb LOG: execute S_1: SELECT = dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.651 CEST [1511] user@testdb LOG: execute S_1: SELECT = dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.653 CEST [1511] user@testdb LOG: execute S_1: SELECT = dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.653 CEST [1511] user@testdb LOG: execute S_1: SELECT = dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.654 CEST [1511] user@testdb LOG: execute S_1: SELECT = dim1 FROM number WHERE name=3D'first' 2023-08-21 11:51:50.656 CEST [1511] user@testdb LOG: execute S_1: SELECT = dim1 FROM number WHERE name=3D=E2=80=98first' Can I do something to avoid this problem? thank you Edoardo