pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Viktor Remennik <vik@etogo.net>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #18780: Bindings types are lost for complex queries
Date: Mon, 20 Jan 2025 14:26:29 -0500
Message-ID: <3077202.1737401189@sss.pgh.pa.us> (raw)
In-Reply-To: <761091B0-E053-4C4E-A112-1F7D8E700EEE@notexi.st>
References: <18780-bae540b8dbfe4cdc@postgresql.org>
	<CAKFQuwauor0qYsPaB1CEu5atYu6H1y1ibcVA0VtgxkLKVyDXig@mail.gmail.com>
	<761091B0-E053-4C4E-A112-1F7D8E700EEE@notexi.st>

Viktor Remennik <vik@etogo.net> writes:
>     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=src.ts,
>                     amount=src.amount
>             when not matched then
>                 insert ("id", "ts", "amount")
>                 values (src.id, src.ts, src.amount)
>             """;

That is never going to work, and you can complain all you want
but we're not going to accept it as a bug.  The sub-select has
to decide on its output column types before parsing can proceed.
There is way too much semantic distance between there and where
it might be possible to discover that the output columns are
going to be assigned to particular target columns; furthermore,
the outer query might have other references to the sub-select's
columns that do not provide usable context for resolving their
types, or that provide conflicting hints.

The only cases like this that we support are

insert into sometable values (?)
insert into sometable select ?
update sometable set somecolumn = ?

where there is basically not anything between the unlabeled
parameter and its single use as an assignment source.  (Even
these are undesirably messy internally.)

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <3077202.1737401189@sss.pgh.pa.us>
Permalink:  ../3077202.1737401189@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3077202.1737401189@sss.pgh.pa.us

 · 

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: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, vik@etogo.net, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18780: Bindings types are lost for complex queries
  In-Reply-To: <3077202.1737401189@sss.pgh.pa.us>

* 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