René's URL Explorer Experiment


Title: Async :many codegen breaks for DML + RETURNING queries (uses .stream() server-side cursor) · Issue #101 · sqlc-dev/sqlc-gen-python · GitHub

Open Graph Title: Async :many codegen breaks for DML + RETURNING queries (uses .stream() server-side cursor) · Issue #101 · sqlc-dev/sqlc-gen-python

X Title: Async :many codegen breaks for DML + RETURNING queries (uses .stream() server-side cursor) · Issue #101 · sqlc-dev/sqlc-gen-python

Description: Summary For :many queries that contain DML + RETURNING (e.g. WITH cte AS (...) UPDATE ... RETURNING ...), the async querier emits await self._conn.stream(...). SQLAlchemy's AsyncConnection.stream() opens a psycopg server-side cursor (DEC...

Open Graph Description: Summary For :many queries that contain DML + RETURNING (e.g. WITH cte AS (...) UPDATE ... RETURNING ...), the async querier emits await self._conn.stream(...). SQLAlchemy's AsyncConnection.stream()...

X Description: Summary For :many queries that contain DML + RETURNING (e.g. WITH cte AS (...) UPDATE ... RETURNING ...), the async querier emits await self._conn.stream(...). SQLAlchemy's AsyncConnection.stre...

Opengraph URL: https://github.com/sqlc-dev/sqlc-gen-python/issues/101

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Async :many codegen breaks for DML + RETURNING queries (uses .stream() server-side cursor)","articleBody":"## Summary\n\nFor `:many` queries that contain DML + `RETURNING` (e.g. `WITH cte AS (...) UPDATE ... RETURNING ...`), the async querier emits `await self._conn.stream(...)`. SQLAlchemy's `AsyncConnection.stream()` opens a psycopg server-side cursor (`DECLARE ... CURSOR FOR ...`), and Postgres rejects DML inside a `DECLARE CURSOR` with `syntax error at or near \"UPDATE\"`. The query is unrunnable from the generated wrapper.\n\nThe sync codepath uses `.execute()` and works correctly for the same SQL — only the async path is affected.\n\n## Reproducer\n\n`schema.sql`\n```sql\nCREATE TABLE widgets (\n    id BIGSERIAL PRIMARY KEY,\n    counter INT NOT NULL DEFAULT 0\n);\n```\n\n`queries.sql`\n```sql\n-- name: BumpWidgets :many\nWITH selected AS (\n    SELECT id FROM widgets WHERE counter \u003c $1 LIMIT $2\n)\nUPDATE widgets\nSET counter = widgets.counter + 1\nFROM selected\nWHERE widgets.id = selected.id\nRETURNING widgets.id, widgets.counter;\n```\n\n`sqlc.yaml`\n```yaml\nversion: \"2\"\nplugins:\n  - name: py\n    wasm:\n      url: https://downloads.sqlc.dev/plugin/sqlc-gen-python_1.3.0.wasm\n      sha256: fbedae96b5ecae2380a70fb5b925fd4bff58a6cfb1f3140375d098fbab7b3a3c\nsql:\n  - schema: \"schema.sql\"\n    queries: \"queries.sql\"\n    engine: postgresql\n    codegen:\n      - plugin: py\n        out: gen\n        options:\n          package: gen\n          emit_async_querier: true\n          emit_sync_querier: false\n```\n\nGenerated wrapper (abridged):\n```python\nasync def bump_widgets(self, *, threshold: int, limit: int) -\u003e AsyncIterator[models.Widget]:\n    result = await self._conn.stream(\n        sqlalchemy.text(BUMP_WIDGETS), {\"p1\": threshold, \"p2\": limit}\n    )\n    async for row in result:\n        yield models.Widget(id=row[0], counter=row[1])\n```\n\nCalling it raises:\n```\npsycopg.errors.SyntaxError: syntax error at or near \"UPDATE\"\nLINE 5: UPDATE widgets\n        ^\n```\n\n## Expected\n\nAsync `:many` should work for the same SQL the sync `:many` path handles correctly today. The CTE + UPDATE + RETURNING pattern is canonical for any batched-update workload.\n\n## Workaround\n\nBypass the generated wrapper and run the SQL through `conn.execute(...)` from app code, importing the SQL constant from the generated module. Survives `sqlc generate` because the generated file is left untouched.\n\n## Suggested fix direction\n\nThe bug is isolated to the async `:many` branch in `internal/gen.go` (~lines 1022-1040). Sync `:many` already uses `execute` correctly. A minimal patch swaps `stream` → `execute` and `AsyncFor` → `For` over an awaited `Result`. Behavioral change: rows are buffered into the result before iteration rather than streamed — same memory profile as the sync path. For very large result sets, an opt-in keeps streaming via a per-query annotation or a config option, but defaulting to `execute` matches sync behavior and avoids the silent DML breakage.\n\nHappy to send a PR if there's interest.\n\n## Environment\n\n- sqlc-gen-python `1.3.0` (downloads.sqlc.dev wasm, sha256 fbedae96…)\n- sqlc CLI `1.31.1`\n- Postgres 18 + psycopg 3 + SQLAlchemy 2.0\n","author":{"url":"https://github.com/jrc2139","@type":"Person","name":"jrc2139"},"datePublished":"2026-05-05T23:34:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/101/sqlc-gen-python/issues/101"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0d39f081-8598-dafb-3526-f832480d5177
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE68:2AE5C2:F923B0:168625E:6A54B3D9
html-safe-nonce90da4ca65d648173fb039eb4c76d37b55da1534d945fff170d0b10716466268c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTY4OjJBRTVDMjpGOTIzQjA6MTY4NjI1RTo2QTU0QjNEOSIsInZpc2l0b3JfaWQiOiI1MTMxMTA3NDA3ODAwNjExODAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac7d126511920952531c96a71cd1c4c07343134e2ca9e181a78b4d8ba297f94940
hovercard-subject-tagissue:4387720383
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlc-dev/sqlc-gen-python/101/issue_layout
twitter:imagehttps://opengraph.githubassets.com/575403bd239978b0a406481837d9461cf1e333975be7fb5336495ba738b788d5/sqlc-dev/sqlc-gen-python/issues/101
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/575403bd239978b0a406481837d9461cf1e333975be7fb5336495ba738b788d5/sqlc-dev/sqlc-gen-python/issues/101
og:image:altSummary For :many queries that contain DML + RETURNING (e.g. WITH cte AS (...) UPDATE ... RETURNING ...), the async querier emits await self._conn.stream(...). SQLAlchemy's AsyncConnection.stream()...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejrc2139
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/sqlc-dev/sqlc-gen-python git https://github.com/sqlc-dev/sqlc-gen-python.git
octolytics-dimension-user_id136738596
octolytics-dimension-user_loginsqlc-dev
octolytics-dimension-repository_id548530161
octolytics-dimension-repository_nwosqlc-dev/sqlc-gen-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id548530161
octolytics-dimension-repository_network_root_nwosqlc-dev/sqlc-gen-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5d343e1152573ef294b28f54e4a14fb5fdb3a5a1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/sqlc-dev/sqlc-gen-python/issues/101#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsqlc-dev%2Fsqlc-gen-python%2Fissues%2F101
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsqlc-dev%2Fsqlc-gen-python%2Fissues%2F101
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=sqlc-dev%2Fsqlc-gen-python
Reloadhttps://github.com/sqlc-dev/sqlc-gen-python/issues/101
Reloadhttps://github.com/sqlc-dev/sqlc-gen-python/issues/101
Reloadhttps://github.com/sqlc-dev/sqlc-gen-python/issues/101
Please reload this pagehttps://github.com/sqlc-dev/sqlc-gen-python/issues/101
sqlc-dev https://github.com/sqlc-dev
sqlc-gen-pythonhttps://github.com/sqlc-dev/sqlc-gen-python
Notifications https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc-gen-python
Fork 50 https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc-gen-python
Star 332 https://github.com/login?return_to=%2Fsqlc-dev%2Fsqlc-gen-python
Code https://github.com/sqlc-dev/sqlc-gen-python
Issues 36 https://github.com/sqlc-dev/sqlc-gen-python/issues
Pull requests 17 https://github.com/sqlc-dev/sqlc-gen-python/pulls
Actions https://github.com/sqlc-dev/sqlc-gen-python/actions
Projects https://github.com/sqlc-dev/sqlc-gen-python/projects
Security and quality 0 https://github.com/sqlc-dev/sqlc-gen-python/security
Insights https://github.com/sqlc-dev/sqlc-gen-python/pulse
Code https://github.com/sqlc-dev/sqlc-gen-python
Issues https://github.com/sqlc-dev/sqlc-gen-python/issues
Pull requests https://github.com/sqlc-dev/sqlc-gen-python/pulls
Actions https://github.com/sqlc-dev/sqlc-gen-python/actions
Projects https://github.com/sqlc-dev/sqlc-gen-python/projects
Security and quality https://github.com/sqlc-dev/sqlc-gen-python/security
Insights https://github.com/sqlc-dev/sqlc-gen-python/pulse
Async :many codegen breaks for DML + RETURNING queries (uses .stream() server-side cursor)https://github.com/sqlc-dev/sqlc-gen-python/issues/101#top
https://github.com/jrc2139
jrc2139https://github.com/jrc2139
on May 5, 2026https://github.com/sqlc-dev/sqlc-gen-python/issues/101#issue-4387720383
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.