pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: BbIKTOP (@BbIKTOP) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #3482: When using java.sql.Timestamp for update, an exception thrown
Date: Fri, 17 Jan 2025 13:33:25 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

Well, workaround wit explicit bindings works fine in both cases:

```

    private static final String MERGE_QUERY = """
                        merge into test as dst
            using (select ? as "id",
                          ? as "ts",
                          ? as amount) src
            on dst."id"=?
            when matched then
                update
                set "ts"=?,
                    amount=?
            when not matched then
                insert ("id", "ts", "amount")
                values (?, ?, ?)
            """;

    @Test
    public void test() throws SQLException
    {
        try (Connection conn = dataSource.getConnection())
        {
            log.info("Driver version {}", conn.getMetaData().getDriverVersion());
            PreparedStatement ps = conn.prepareStatement(MERGE_QUERY);

            Integer id = 1;
            Timestamp ts = Timestamp.valueOf(LocalDateTime.now());
            Integer amount = 123;

            ps.setObject(1, id);
            ps.setObject(2, ts);
            ps.setObject(3, amount);
            ps.setObject(4, id);

            ps.setObject(5, ts);
            ps.setObject(6, amount);
            ps.setObject(7, id);
            ps.setObject(8, ts);
            ps.setObject(9, amount);

            ps.executeUpdate();
        } catch (Exception e)
        {
            log.error(e.getMessage(), e);
        }
    }

```

view thread (48+ messages)  latest in thread

reply

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: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #3482: When using java.sql.Timestamp for update, an exception thrown
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox