Title: Can't get current value of sequence · Issue #1634 · sqlc-dev/sqlc · GitHub
Open Graph Title: Can't get current value of sequence · Issue #1634 · sqlc-dev/sqlc
X Title: Can't get current value of sequence · Issue #1634 · sqlc-dev/sqlc
Description: Version 1.13.0 What happened? When trying to obtain the last value used in a sequence by using SELECT last_value FROM my_sequence the generate step fails complaining that the relation my_sequence does not exist. That kind of query is doc...
Open Graph Description: Version 1.13.0 What happened? When trying to obtain the last value used in a sequence by using SELECT last_value FROM my_sequence the generate step fails complaining that the relation my_sequence d...
X Description: Version 1.13.0 What happened? When trying to obtain the last value used in a sequence by using SELECT last_value FROM my_sequence the generate step fails complaining that the relation my_sequence d...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/1634
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Can't get current value of sequence","articleBody":"### Version\n\n1.13.0\n\n### What happened?\n\nWhen trying to obtain the last value used in a sequence by using `SELECT last_value FROM my_sequence` the generate step fails complaining that the relation `my_sequence` does not exist. That kind of query is documented in the [`CREATE SEQUENCE` documentation](https://www.postgresql.org/docs/current/sql-createsequence.html) for postgres:\r\n\r\n\u003e Although you cannot update a sequence directly, you can use a query like:\r\n\u003e \r\n\u003e ```\r\n\u003e SELECT * FROM name;\r\n\u003e ```\r\n\u003e \r\n\u003e to examine the parameters and current state of a sequence. In particular, the last_value field of the sequence shows the last value allocated by any session. (Of course, this value might be obsolete by the time it's printed, if other sessions are actively doing nextval calls.)\r\n\r\nUsing `SELECT currval('my_sequence')` does not work for me because it returns the last value for that sequence _in the current session_ (see [documentation](https://www.postgresql.org/docs/current/functions-sequence.html)).\r\n\r\nThe issue seems to be that the `sqlc` parser identifies `my_sequence` as a table in the `SELECT last_value FROM my_sequence` but does not find such table in the schema (internally it seems that sequences are special one-row tables).\n\n### Relevant log output\n\n```shell\nsqlc generate failed.\r\n# package db\r\nquery.sql:11:1: relation \"my_sequence\" does not exist\n```\n\n\n### Database schema\n\n```sql\nCREATE SEQUENCE public.my_sequence\r\n START WITH 1\r\n INCREMENT BY 1\r\n NO MINVALUE\r\n NO MAXVALUE\r\n CACHE 1;\n```\n\n\n### SQL queries\n\n```sql\n-- name: GetLastValue :one\r\nSELECT last_value FROM my_sequence;\n```\n\n\n### Configuration\n\n```yaml\n{\r\n \"version\": \"1\",\r\n \"packages\": [\r\n {\r\n \"path\": \"db\",\r\n \"engine\": \"postgresql\",\r\n \"schema\": \"query.sql\",\r\n \"queries\": \"query.sql\"\r\n }\r\n ]\r\n}\n```\n\n\n### Playground URL\n\nhttps://play.sqlc.dev/p/75805a902ff7fa9eaa6241d9fb4cf48f4cd809184d2ff39d4adec0a3412b69e8\n\n### What operating system are you using?\n\nmacOS\n\n### What database engines are you using?\n\nPostgreSQL\n\n### What type of code are you generating?\n\nGo","author":{"url":"https://github.com/kampde","@type":"Person","name":"kampde"},"datePublished":"2022-05-19T22:50:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1634/sqlc/issues/1634"}
| 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:004d3eac-8d9f-f9e7-83fe-e560a8b8446a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F52:159AA0:AAA83:E974E:6A50F42A |
| html-safe-nonce | e81e0f5c0c424bf87b8473260f2e4594982a21149a1c9f18d890de5953ac426d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjUyOjE1OUFBMDpBQUE4MzpFOTc0RTo2QTUwRjQyQSIsInZpc2l0b3JfaWQiOiI5MjIzMjczNjA2NTc3OTc2MzYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9fa773846e2aa3261eb42518f5f51fc8258b858dd623c3908fb17c9688545714 |
| hovercard-subject-tag | issue:1242406313 |
| 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/1634/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eabfe25534c96a14f7e07ebb86c2ddc6e2f4dbfc427766ff1a65d6a70227879d/sqlc-dev/sqlc/issues/1634 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eabfe25534c96a14f7e07ebb86c2ddc6e2f4dbfc427766ff1a65d6a70227879d/sqlc-dev/sqlc/issues/1634 |
| og:image:alt | Version 1.13.0 What happened? When trying to obtain the last value used in a sequence by using SELECT last_value FROM my_sequence the generate step fails complaining that the relation my_sequence d... |
| 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 | 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 |
| 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 | 5ec60191a48933536a90c8a19f47142fcd0d4739 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width