Re: Proposal to allow setting cursor options on Portals

Dave Cramer <davecramer@gmail.com>

From: Dave Cramer <davecramer@gmail.com>
To: Jelte Fennema-Nio <postgres@jeltef.nl>
Cc: Sami Imseih <samimseih@gmail.com>, Hannu Krosing <hannuk@google.com>, Robert Haas <robertmhaas@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Jacob Champion <jacob.champion@enterprisedb.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Heikki Linnakangas <hlinnaka@iki.fi>
Date: 2026-03-25T14:34:42Z
Lists: pgsql-hackers

Attachments

On Wed, 25 Mar 2026 at 03:46, Jelte Fennema-Nio <postgres@jeltef.nl> wrote:

> On Tue, 24 Mar 2026 at 11:01, Dave Cramer <davecramer@gmail.com> wrote:
> > _pq_.cursor would be fine.
>
> I think that makes sense as a name for the option. I think adding flag
> support for SCROLL and NO SCROLL would make sense in that case.
>
> Some notes on the patch (but I didn't look look at the client side
> libpq code in detail):
>
> For the protocol definition I'd like a few changes:
> 1. I'd like the new field in the bind message that you add to be
> described as an extension bitmap, not specifically for cursor options,
> so that future extensions could add bits too it too.
> 2. Related to that, I think the used bits should not align with the
> internal bits. Having the only valid flag bit be 0x0020 is kinda
> weird. Let's just make that 0x0001. We could update the internal ones
> to match if desired, but I think it's fine for the protocol bits to
> differ from the bits in the postgres server.
>
> Docs still mention CURSOR_OPT_BINARY, but support for that has been
> removed from the code afaict (which I think is indeed what should
> happen)
>
> There's a bunch of protocol version 3.3 code still around, which
> should be removed now that the protocol option is added.
>
> PQsendBindWithCursorOptions and PQsendQueryPreparedWithCursorOptions
> should error out if conn->holdable_portal_enabled is false. Right now
> it silently skips the cursor options if the connection does not
> support the protocol extension.
>
> There should be a libpq function to inspect whether the connection
> supports cursor options, so some kind of graceful fallback logic can
> be implemented by the application when it's not supported.
>
> libpq docs are missing
>

Attached is v4 of the patch
Co-Authored by Sami Imseih

Adds docs and test module

Dave

Commits

  1. Fix distinctness check for queries with grouping sets

  2. Provide for forward compatibility with future minor protocol versions.