pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: arthur.mcgibbon@gmail.com
Subject: BUG #17052: Incorrect params inferred on PREPARE (part 2)
Date: Tue, 08 Jun 2021 11:27:51 +0000
Message-ID: <17052-0bb053c08bb80fb6@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17052
Logged by:          Arthur McGibbon
Email address:      arthur.mcgibbon@gmail.com
PostgreSQL version: 13.3
Operating system:   Windows + wsl2 + docker
Description:        

Using the table...

  CREATE TABLE testSchema.testTable (timestampCol timestamp);

...and preparing the query...

  PREPARE testQuery (unknown) AS
  UPDATE testSchema.testTable
  SET timestampCol = $1 + interval '1 minute';

...results in an error...

ERROR:  column "timestampcol" is of type timestamp without time zone but
expression is of type interval
LINE 4:   set timestampCol = $1 + interval '1 minute';
                             ^
HINT:  You will need to rewrite or cast the expression.
SQL state: 42804
Character: 82

Specifying the parameter as timestamp works without error...
  PREPARE testQuery (timestamp) AS
  UPDATE testSchema.testTable
  SET timestampCol = $1 + interval '1 minute';

as does casting...
  PREPARE testQuery (unknown) AS
  UPDATE testSchema.testTable
  SET timestampCol = cast($1 as timestamp) + interval '1 minute';


I'd hope that PostgreSQL would infer a "timestamp" type here instead of an
interval type

It seems in this case (and possibly in bug report 17051) Postgres uses only
a section of the expression to evaluate the parameter type i.e. "$1 +
interval '1 minute'" and assumes that only an interval type can be added to
an interval type but there are a number of types that can be added to an
interval type and ideally it would take into account the result of the
expression which has to be a timestamp (because of the definition of the
timestampCol column) and so work out that the only (or best) way to achieve
that is to have $1 be of type timestamp.



view thread (3+ messages)  latest in thread

Message-ID: <17052-0bb053c08bb80fb6@postgresql.org>
Permalink:  ../17052-0bb053c08bb80fb6@postgresql.org/
Also on:    postgresql.org/message-id/17052-0bb053c08bb80fb6@postgresql.org

 · 

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: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, arthur.mcgibbon@gmail.com
  Subject: Re: BUG #17052: Incorrect params inferred on PREPARE (part 2)
  In-Reply-To: <17052-0bb053c08bb80fb6@postgresql.org>

* 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