Re: Cleaning up PREPARE query strings?

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Sami Imseih <samimseih(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Cleaning up PREPARE query strings?
Date: 2026-01-25 12:57:31
Message-ID: aXYTOw_1GXq0oMaq@jrouhaud
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Jan 19, 2026 at 12:43:53AM -0600, Sami Imseih wrote:
>
> However, the error reporting does break with the patch. Notice with the patch
> the cursor for the error reporting shifts incorrectly. This is due to the fact
> rawstmt->stmt_location/length are no longer representative of the original
> qurey text.
>
> ## unpatched
> ```
> postgres=# SELECT 1 \; PREPARE stmt AS SELECT nonexistent_column
> FROM users\; SELECT 2;
> ?column?
> ----------
> 1
> (1 row)
>
> ERROR: relation "users" does not exist
> LINE 1: ... ; PREPARE stmt AS SELECT nonexistent_column FROM users; SEL...
>
> ^
> ```
>
> ## patched
> ```
> postgres=# SELECT 1 \; PREPARE stmt AS SELECT nonexistent_column
> FROM users\; SELECT 2;
> ?column?
> ----------
> 1
> (1 row)
>
> ERROR: relation "users" does not exist
> LINE 1: ...LECT 1 ; PREPARE stmt AS SELECT nonexistent_column FROM u...
>
> ^
> ```

This was already reported by Tom Lane on his first message, although his
complaint was about execution time error reporting while this is during
parse-analysis. However, I think that the exact same approach can be used to
fixed both, either updating the position of every single element (which no one
wants) or teaching the executor (and evidently the planstate) about a new
"query offset" so that parser_errposition and executor_errposition report the
correct location. I'm still waiting on whether the latter would be acceptable
or not before implementing it. Note that I wasn't able to hit the execution
time error so at least with parse-analysis time error I could at least have
some regression tests, so thanks a lot!

In the meantime, the cfbot shows that a rebase is needed, so v3 attached.

Attachment Content-Type Size
v3-0001-Cleanup-explicit-PREPARE-query-strings.patch text/plain 14.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2026-01-25 13:20:20 Re: unnecessary executor overheads around seqscans
Previous Message Jelte Fennema-Nio 2026-01-25 12:54:35 Re: RFC: adding pytest as a supported test framework