Skip to content

Comments

pq: simple support for named parameters#846

Closed
jeromedoucet wants to merge 2 commits intolib:masterfrom
jeromedoucet:master
Closed

pq: simple support for named parameters#846
jeromedoucet wants to merge 2 commits intolib:masterfrom
jeromedoucet:master

Conversation

@jeromedoucet
Copy link

what:
Add named parameters support for "conn". It works basically like ordinals
parameters, but with an alphabetical label prefixed with ":"

Example:

Select $1, $2, $1; may become Select :firstName, :lastName, :firstName

Why:
SQL queries may be difficult to maintain, especially when the complexity
is growing. Ordinal parameters are great, but may not be meaningfull for
the one who is trying to understand the query.

The goal here is not to have something full featured and complex : pq is
"just" a driver, but having a thin layer, simple to maintain, that will
fit 90% of the needs.

Limitations:
Its simplicity means that there is many limitations :

First of all, using mixed types of parameters is not
allowed. Man can not use ordinal parameters and named
parameters is the same query.

Refs #534

what:
Add named parameters support for "conn". It works basically like ordinals
parameters, but with an alphabetical label prefixed with ":"

Example:

Select $1, $2, $1; may become Select :firstName, :lastName, :firstName

Why:
SQL queries may be difficult to maintain, especially when the complexity
is growing. Ordinal parameters are great, but may not be meaningfull for
the one who is trying to understand the query.

The goal here is not to have something full featured and complex : pq is
"just" a driver, but having a thin layer, simple to maintain, that will
fit 90% of the needs.

Limitations:
Its simplicity means that there is many limitations :

First of all, using mixed types of parameters is not
allowed. Man can not use ordinal parameters and named
parameters is the same query.

Refs lib#534
Add explicit cast for some postgres version.

Refs lib#534
@Congee
Copy link

Congee commented Jun 4, 2020

any blocker?

@arp242
Copy link
Collaborator

arp242 commented Dec 31, 2025

I'm quite hesitant to use a regexp-based solution for this, as per my comment in #534 (comment)

While this at least avoids the col::text problem that sqlx has, it will also replace things in comments and string literals, which is not really correct and may result in weird/confusing logs and pg_stat_statements at best, and malformed SQL at worst.

@arp242 arp242 added the needs-feedback Requires feedback to be actionable label Dec 31, 2025
@arp242 arp242 closed this Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-feedback Requires feedback to be actionable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants