Title: Redesign the row methods of the DB wrapper · Issue #126 · PyGreSQL/PyGreSQL · GitHub
Open Graph Title: Redesign the row methods of the DB wrapper · Issue #126 · PyGreSQL/PyGreSQL
X Title: Redesign the row methods of the DB wrapper · Issue #126 · PyGreSQL/PyGreSQL
Description: The row methods of the DB wrapper (get(), insert(), update(), upsert(), delete()) have grown over time. Their API was designed around tables with OIDs, which no longer exist since PostgreSQL 12, and it has several inconsistencies that ca...
Open Graph Description: The row methods of the DB wrapper (get(), insert(), update(), upsert(), delete()) have grown over time. Their API was designed around tables with OIDs, which no longer exist since PostgreSQL 12, an...
X Description: The row methods of the DB wrapper (get(), insert(), update(), upsert(), delete()) have grown over time. Their API was designed around tables with OIDs, which no longer exist since PostgreSQL 12, an...
Opengraph URL: https://github.com/PyGreSQL/PyGreSQL/issues/126
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Redesign the row methods of the DB wrapper","articleBody":"The row methods of the `DB` wrapper (`get()`, `insert()`, `update()`, `upsert()`, `delete()`) have grown over time. Their API was designed around tables with OIDs, which no longer exist since PostgreSQL 12, and it has several inconsistencies that cannot be fixed without breaking changes. I'd like to redesign them in 7.0. This issue describes the problems and collects suggestions. It does not decide on the new API yet.\n\nFor 6.3, I'm adding a `keyname` parameter to `update()`, `delete()` and `upsert()` like the one in `get()`, so tables without a primary key can be used (#56), and removing the remaining OID support. These changes are backward compatible, but the problems below remain.\n\n## Problems\n\n- **Keyword arguments mean different things.** In `insert()`, `update()` and `delete()`, keyword arguments are column values that are merged into the row dict. In `upsert()`, they are rules for updating columns on conflict (`True`, `False`/`None` or an SQL expression).\n- **Parameter names collide with column names.** Since columns are passed as keyword arguments, columns named `table`, `row` or `keyname` cannot be passed that way. For `upsert()`, no update rule can be given for such a column at all.\n- **Awkward \"do nothing\".** To leave an existing row unchanged, you have to call `upsert(table, row, **dict.fromkeys(row))`. `ON CONFLICT DO NOTHING` without a conflict target, conflicts on a constraint name (needed for exclusion constraints), and `WHERE` clauses cannot be expressed.\n- **The passed dict is modified in place** and also returned. This side effect is surprising, and in `upsert()` it is the only way to get the result.\n- **Errors pass silently.** `update()` returns the row unchanged if no row matches the key, so the caller cannot tell whether anything was updated. `get()` raises a `DatabaseError` in this case, and `delete()` returns the number of deleted rows.\n- **Leftovers of the OID design.** The `oid(table)` keys, the `oid` keyword for identifying rows, and the `with_oid` parameter of `get_attnames()`.\n- **Table names** are handled inconsistently, see #67 (schema-qualified names, the `*` suffix for descendant tables).\n\n## Suggestions (to be discussed)\n\n- Pass column values only in the row (a dict or keyword arguments, but not both), and make all options keyword-only with names that are clearly not column names. Or the opposite: keep `**kw` for column values only, and move the update rules of `upsert()` to a parameter, e.g. `upsert(table, row, keyname=None, update=None)` where `update` is a list of columns or a dict of columns to `True`/`False`/SQL expressions, and an empty list means `DO NOTHING`.\n- Return a new dict instead of modifying the passed one, or make this an option.\n- Let `update()` signal a missing row like `get()` (raise an exception), or return `None`.\n- Support conflict targets given as columns or as a constraint name, and optionally `DO NOTHING` without a target.\n- Look at how others do it: psycopg 3 has no such helpers. SQLAlchemy has `insert().on_conflict_do_update(index_elements=..., constraint=..., set_=..., where=...)` and `on_conflict_do_nothing()`. Django has `bulk_create(update_conflicts=True, unique_fields=..., update_fields=...)`.\n- Transition: new method names, or deprecation warnings in a 6.x release before changing the existing methods.\n","author":{"url":"https://github.com/Cito","@type":"Person","name":"Cito"},"datePublished":"2026-11-22T18:41:12Z","url":"https://github.com/PyGreSQL/PyGreSQL/issues/126"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5d5fbfa1-d404-a9f0-fc99-84b224ada586 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 856C:154661:35B58:4BA00:6B046167 |
| html-safe-nonce | dcafd50cc08070520563378aab7d74f3c202a54bd85d985d27b4212a2e117e79 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTZDOjE1NDY2MTozNUI1ODo0QkEwMDo2QjA0NjE2NyIsInZpc2l0b3JfaWQiOiI4MTExNTUwMzY0NTg4OTkwODIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0e7b873ec847126aa0ff7e8d2f823e797943ac4cfaf608325373e8b6216e3ed6 |
| hovercard-subject-tag | issue:6546209826 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PyGreSQL/PyGreSQL/126/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a43e457f220809f079b7f04fb86d4559b07ae3dbbc51c40c42ec39fcefad8510/PyGreSQL/PyGreSQL/issues/126 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a43e457f220809f079b7f04fb86d4559b07ae3dbbc51c40c42ec39fcefad8510/PyGreSQL/PyGreSQL/issues/126 |
| og:image:alt | The row methods of the DB wrapper (get(), insert(), update(), upsert(), delete()) have grown over time. Their API was designed around tables with OIDs, which no longer exist since PostgreSQL 12, an... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Cito |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6 |
| turbo-cache-control | no-preview |
| go-import | github.com/PyGreSQL/PyGreSQL git https://github.com/PyGreSQL/PyGreSQL.git |
| octolytics-dimension-user_id | 60857770 |
| octolytics-dimension-user_login | PyGreSQL |
| octolytics-dimension-repository_id | 51212044 |
| octolytics-dimension-repository_nwo | PyGreSQL/PyGreSQL |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 51212044 |
| octolytics-dimension-repository_network_root_nwo | PyGreSQL/PyGreSQL |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 03e114520787ad27289207f153520ef97461127c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width