From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Manav Kumar <mkumar@yugabyte.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: Understanding JDBC Behaviour
Date: Mon, 19 May 2025 09:15:56 +0200
Message-ID: <21e42f9bc769d8b863ce660c508c6a50930a504c.camel@cybertec.at> (raw)
In-Reply-To: <CAPhCW+-bC8URy_vi5MBDj3c5yB0A40nbDy1sGHLqC3L+p+9HBQ@mail.gmail.com>
References: <CAPhCW+-bC8URy_vi5MBDj3c5yB0A40nbDy1sGHLqC3L+p+9HBQ@mail.gmail.com>
On Sat, 2025-05-17 at 18:05 +0530, Manav Kumar wrote:
> I'm writing to clarify a syntax to pass the guc options in the startup packt of the connection via JDBC.
>
>
> Wrote below small java program:
>
> Properties props = new Properties();
> props.setProperty("options", "-c DateStyle=Postgres,DMY");
> props.setProperty("user", "postgres");
> props.setProperty("password", "postgres");
> connection = DriverManager.getConnection(
> "jdbc:postgresql://localhost:5432/postgres", props);
>
> stmt1 = connection.createStatement();
> ResultSet rs = stmt1.executeQuery("show DateStyle");
> while (rs.next()) {
> System.out.println(rs.getString(1));
> }
> stmt1.execute("reset DateStyle");
> rs = stmt1.executeQuery("show DateStyle");
> while (rs.next()) {
> System.out.println(rs.getString(1));
> }
>
> The output I'm getting is:
> ISO, DMY
> ISO, DMY.
>
> Rather shouldn't the expected output should be
> Postgres, DMY
> Postgres, DMY //Please correct me - Even after the reset the default value should be Postgres, DMY ?
> I checked the official docs, and found the syntax above.
> Looking forward to seeing your response! Please let me know if I should post elsewhere.
The correct list would have been pgsql-jdbc, but I'll answer here.
There is no bug involved. The behavior can be explained as follows:
1. The PostgreSQL JDBC driver forces "DateStyle" to "ISO", because it needs that setting
to handle dates and timestamps correctly. If you manage to change the setting, the
driver will fail with the error message:
The server''s DateStyle parameter was changed to ....
The JDBC driver requires DateStyle to beegin with ISO for correct operation.
2. RESET will reset the parameter to what it was when the session started.
Yours,
Laurenz Albe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: laurenz.albe@cybertec.at, mkumar@yugabyte.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Understanding JDBC Behaviour
In-Reply-To: <21e42f9bc769d8b863ce660c508c6a50930a504c.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox