Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default value in insert&update #214

Open
baest opened this issue Dec 10, 2021 · 1 comment
Open

Support default value in insert&update #214

baest opened this issue Dec 10, 2021 · 1 comment
Assignees

Comments

@baest
Copy link

baest commented Dec 10, 2021

Currently it doesn't seem there is any why of inserting or updating with a default value like:

insert into users (id, firstname, lastname) values (default, 'Arthur', 'Dent');

or

update users set id = default where ...

I can see DBD::Pg implements this with a special variable: $DBD::Pg::DBDPG_DEFAULT and handles replacing ? $\d with DEFAULT.

@rbt
Copy link
Collaborator

rbt commented Dec 17, 2021

This is trickier than it first appears, particularly since nearly everything we do with Pg is done via a prepared statement and replacing ? or $1 with the DEFAULT keyword changes the statement which doesn't help performance for repeated executions.

Detecting the special $DEFAULT value in the parameter list would be cheap but I think execution would need to give up the few optimizations the driver does have.

It would be nice if it could be a server-side feature rather than implemented in the driver but that looks clumsy to wedge into libpq's PqExecParams() without a protocol break. At best you could set aside an unused type OID and push it through paramTypes.

@rbt rbt self-assigned this Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants