Title: Insert statement with `WITH` clause used as `SELECT` field · Issue #2886 · sqlc-dev/sqlc · GitHub
Open Graph Title: Insert statement with `WITH` clause used as `SELECT` field · Issue #2886 · sqlc-dev/sqlc
X Title: Insert statement with `WITH` clause used as `SELECT` field · Issue #2886 · sqlc-dev/sqlc
Description: Version 1.22.0 What happened? This is similar to #2350. I've tried 2 variations of the same query using WITH (v AS ...) and referencing that v as one of the SELECTed fields. While both variations produce the expected results using psql, ...
Open Graph Description: Version 1.22.0 What happened? This is similar to #2350. I've tried 2 variations of the same query using WITH (v AS ...) and referencing that v as one of the SELECTed fields. While both variations p...
X Description: Version 1.22.0 What happened? This is similar to #2350. I've tried 2 variations of the same query using WITH (v AS ...) and referencing that v as one of the SELECTed fields. While both variatio...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/2886
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Insert statement with `WITH` clause used as `SELECT` field","articleBody":"### Version\r\n\r\n1.22.0\r\n\r\n### What happened?\r\n\r\nThis is similar to #2350.\r\n\r\nI've tried 2 variations of the same query using `WITH (v AS ...)` and referencing that `v` as one of the `SELECT`ed fields. While both variations produce the expected results using `psql`, they fail with different errors when compiling them using `sqlc`.\r\n\r\n1. Using `INSERT INTO ... WITH ... SELECT ...\r\n \r\n ```sql\r\n -- name: GenerateNewHistoricalData :exec\r\n INSERT INTO historical_data(id, default_value, version)\r\n WITH v AS (SELECT nextval('historical_data_version_seq'))\r\n SELECT id, default_value, (table v)\r\n FROM data;\r\n ```\r\n **Error**: `query.sql:18:1: relation \"v\" does not exist`\r\n\r\n2. Using `WITH ... INSERT INTO ... SELECT ...`:\r\n\r\n ```sql\r\n -- name: GenerateNewHistoricalDataTakeTwo :exec\r\n WITH v AS (SELECT nextval('historical_data_version_seq'))\r\n INSERT INTO historical_data(id, default_value, version)\r\n SELECT id, default_value, (table v)\r\n FROM data;\r\n ```\r\n **Error**: `query.sql:24:1: edit start location is out of bounds`\r\n\r\n\r\n### Relevant log output\r\n\r\n_No response_\r\n\r\n### Database schema\r\n\r\n```sql\r\nCREATE TABLE data (\r\n id TEXT NOT NULL,\r\n value TEXT NOT NULL,\r\n CONSTRAINT data_pkey PRIMARY KEY(id)\r\n);\r\n\r\nCREATE TABLE historical_data (\r\n id TEXT NOT NULL,\r\n value TEXT NOT NULL,\r\n version BIGINT NOT NULL,\r\n CONSTRAINT historical_data_pkey PRIMARY KEY(id, version)\r\n);\r\n\r\nCREATE SEQUENCE historical_data_version_seq;\r\n```\r\n\r\n### SQL queries\r\n\r\n_No response_\r\n\r\n### Configuration\r\n\r\n_No response_\r\n\r\n### Playground URL\r\n\r\nhttps://play.sqlc.dev/p/4c877cf26c2bb27c217303995af1afbef3bf9c84a25e682f01de5f0745c259cc\r\n\r\n### What operating system are you using?\r\n\r\nmacOS\r\n\r\n### What database engines are you using?\r\n\r\nPostgreSQL\r\n\r\n### What type of code are you generating?\r\n\r\nGo","author":{"url":"https://github.com/kampde","@type":"Person","name":"kampde"},"datePublished":"2023-10-19T12:00:04.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2886/sqlc/issues/2886"}
| 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:3d267525-0fe4-82d1-8421-70d76a7e9dda |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CFEE:3A06E8:7E0F8E:B2527C:6A51046F |
| html-safe-nonce | 5857920934e74184f27b9f4bcf6dcb389ab7976baa8930e347e908f3517fbe03 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRkVFOjNBMDZFODo3RTBGOEU6QjI1MjdDOjZBNTEwNDZGIiwidmlzaXRvcl9pZCI6IjU0NjEyNjU3NDAwMjY5Mzg0ODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 496617491e04f44e485dddd385e3e8fa11647c33f9f48976f74da9e9ecd8f7aa |
| hovercard-subject-tag | issue:1952044297 |
| 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/sqlc-dev/sqlc/2886/issue_layout |
| twitter:image | https://opengraph.githubassets.com/31753cc5284608990a39d7874c610754d8d49f718bc966f58fd72d6f60461936/sqlc-dev/sqlc/issues/2886 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/31753cc5284608990a39d7874c610754d8d49f718bc966f58fd72d6f60461936/sqlc-dev/sqlc/issues/2886 |
| og:image:alt | Version 1.22.0 What happened? This is similar to #2350. I've tried 2 variations of the same query using WITH (v AS ...) and referencing that v as one of the SELECTed fields. While both variations p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kampde |
| hostname | github.com |
| expected-hostname | github.com |
| None | 38906a4da4e3e9fd88dfeacee232f5932c0c5f7495de3b4efc53ddfac7173d12 |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 193160679 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 193160679 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc |
| 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 | 90441ea9b98e7491aa6ebcd135fccce4e2396f48 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width