CockroachDB implements SQL cursor support with the following limitations:
DECLARE only supports forward cursors. Reverse cursors created with DECLARE SCROLL are not supported.
FETCH supports forward, relative, and absolute variants, but only for forward cursors.
BINARY CURSOR, which returns data in the Postgres binary format, is not supported.
WITH HOLD, which allows keeping a cursor open for longer than a transaction by writing its results into a buffer, is accepted as valid syntax within a single transaction but is not supported. It acts as a no-op and does not actually perform the function of WITH HOLD, which is to make the cursor live outside its parent transaction. Instead, if you are using WITH HOLD, you will be forced to close that cursor within the transaction it was created in.
This syntax is accepted (but does not have any effect):
BEGIN;DECLARE test_cur CURSOR WITH HOLD FOR SELECT * FROM foo ORDER BY bar;CLOSE test_cur;COMMIT;
This syntax is not accepted, and will result in an error:
BEGIN;DECLARE test_cur CURSOR WITH HOLD FOR SELECT * FROM foo ORDER BY bar;COMMIT; -- This will fail with an error because CLOSE test_cur was not called inside the transaction.
Scrollable cursor (also known as reverse FETCH) is not supported.
with a cursor is not supported.
Respect for is not supported. Cursor definitions do not disappear properly if rolled back to a SAVEPOINT from before they were created.
Cursors are stateful objects that use more database resources than keyset pagination, since each cursor holds open a transaction. However, they are easier to use, and make it easier to get consistent results without having to write complex queries from your application logic. They do not require that the results be returned in a particular order (that is, you don’t have to include an ORDER BY clause), which makes them more flexible.Keyset pagination queries are usually much faster than cursors since they order by indexed columns. However, in order to get that performance they require that you return results in some defined order that can be calculated by your application’s queries. Because that ordering involves calculating the start/end point of pages of results based on an indexed key, they require more care to write correctly.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"CockroachDB","colors":{"primary":"#9059FF","light":"#9059FF","dark":"#9059FF"},"logo":{"light":"https://mintcdn.com/cockroachlabs/4WvUnbVuGZfqM4kW/images/CockroachLabs_Wordmark_Black.png?fit=max\u0026auto=format\u0026n=4WvUnbVuGZfqM4kW\u0026q=85\u0026s=54ccae625c9986bf1df8ddc7b2c571f0","dark":"https://mintcdn.com/cockroachlabs/4WvUnbVuGZfqM4kW/images/CockroachLabs_Wordmark_White.png?fit=max\u0026auto=format\u0026n=4WvUnbVuGZfqM4kW\u0026q=85\u0026s=0dd9b66973a1c7d3dd72aa67b6094efe","href":"https://www.cockroachlabs.com/"},"favicon":{"light":"https://mintcdn.com/cockroachlabs/2yihO7vMXnL0G_07/images/favicon.svg?fit=max\u0026auto=format\u0026n=2yihO7vMXnL0G_07\u0026q=85\u0026s=01f9aa59c9f275e1f35cd424a27d2551","dark":"https://mintcdn.com/cockroachlabs/2yihO7vMXnL0G_07/images/favicon.svg?fit=max\u0026auto=format\u0026n=2yihO7vMXnL0G_07\u0026q=85\u0026s=01f9aa59c9f275e1f35cd424a27d2551"},"api":{"examples":{"defaults":"required","languages":["curl"]}},"appearance":{"default":"light"},"navbar":{"primary":{"type":"button","label":"Get started free","href":"https://cockroachlabs.cloud/signup?referralId=cc_nav_global\u0026_ga=2.242886210.1147139380.1759903632-41552699.1759903632"}},"footer":{"socials":{"youtube":"https://www.youtube.com/@cockroachdb","x":"https://x.com/CockroachDB","linkedin":"https://www.linkedin.com/company/cockroach-labs/mycompany/verification","instagram":"https://www.instagram.com/cockroachdb"},"links":[{"header":"Product","items":[{"label":"CockroachDB","href":"https://www.cockroachlabs.com/product"},{"label":"CockroachDB Cloud","href":"https://www.cockroachlabs.com/product/cockroachcloud"},{"label":"Compare","href":"https://www.cockroachlabs.com/compare"},{"label":"Pricing","href":"https://www.cockroachlabs.com/pricing"},{"label":"Get CockroachDB","href":"https://www.cockroachlabs.com/get-started-cockroachdb"},{"label":"Sign In","href":"https://cockroachlabs.cloud/"}]},{"header":"Resources","items":[{"label":"Guides","href":"https://resources.cockroachlabs.com/guides"},{"label":"Webinars","href":"https://www.cockroachlabs.com/community/webinars"},{"label":"Videos","href":"https://www.cockroachlabs.com/resources/video"},{"label":"Architecture Overview","href":"https://www.cockroachlabs.com/docs/stable/architecture/overview"},{"label":"FAQ","href":"https://www.cockroachlabs.com/docs/stable/frequently-asked-questions"},{"label":"Security","href":"https://www.cockroachlabs.com/security"}]},{"header":"Learn \u0026 Support","items":[{"label":"Docs","href":"https://www.cockroachlabs.com/docs"},{"label":"University","href":"https://learn.cockroachlabs.com/"},{"label":"Developers","href":"https://www.cockroachlabs.com/developers"},{"label":"Forum","href":"https://forum.cockroachlabs.com/"},{"label":"Slack","href":"https://cockroa.ch/slack"},{"label":"Support Portal","href":"https://support.cockroachlabs.com/hc/en-us"},{"label":"Contact Us","href":"https://www.cockroachlabs.com/contact"}]},{"header":"Company","items":[{"label":"About","href":"https://www.cockroachlabs.com/about"},{"label":"Blog","href":"https://www.cockroachlabs.com/blog"},{"label":"Careers","href":"https://www.cockroachlabs.com/careers"},{"label":"Customers","href":"https://www.cockroachlabs.com/customers"},{"label":"News","href":"https://www.cockroachlabs.com/press"},{"label":"Privacy","href":"https://www.cockroachlabs.com/privacy"},{"label":"Terms of Use","href":"https://www.cockroachlabs.com/website-terms-of-use"}]}]},"fonts":{"heading":{"family":"Poppins"},"body":{"family":"Open Sans"}},"styling":{"eyebrows":"breadcrumbs","codeblocks":{"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}},"latex":true},"integrations":{"gtm":{"tagId":"GTM-NR8LC4"}},"errors":{"404":{"redirect":false,"title":"Page not found","description":"The page you're looking for doesn't exist. [Return to docs home](/index.html)."}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","cursor","vscode"],"display":"header"},"interaction":{"drilldown":false},"navigation":{"global":{"anchors":[{"anchor":"University","icon":"graduation-cap","href":"https://learn.cockroachlabs.com/"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"cockroachlabs","hasAudioNarration":false,"actualSubdomain":"cockroachlabs","customDomains":["docs.cockroachlabs.com"],"gitSource":{"type":"github","owner":"cockroachlabs","repo":"docs","deployBranch":"main","contentDirectory":"cockroachlabs-preview-main","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6aecaeb7b150e8092320a8ec","collectionId":"ca0fa18e-bf52-437f-95dc-7da1fd39edbb","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6aecaeb7b150e8092320a8ec"},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"REMOVE_BRANDING":{"status":"ENABLED"},"CONTEXTUAL_FEEDBACK":{"status":"ENABLED"},"CODE_SNIPPET_FEEDBACK":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6aedf6547caf8c60034a2641","clientVersion":"0.0.4076","searchFilterCounts":[{"language":"default","tag":"CockroachDB","count":6950},{"language":"default","tag":"Docs","count":3216},{"language":"default","tag":"SQL","count":2566},{"language":"default","tag":"Statements","count":1714},{"language":"default","tag":"Self-Hosted Deployments","count":1456},{"language":"default","tag":"Reference","count":774},{"language":"default","tag":"Cloud Deployments","count":616},{"language":"default","tag":"Endpoints","count":528},{"language":"default","tag":"Cloud API Reference","count":518},{"language":"default","tag":"Get Started","count":441}],"searchSettings":{"isFiltersEnabled":true,"showContentSnippets":true,"fullPageSearch":true}},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":true,"toggles":[],"googleFontsInlined":true},"customCss":[{"filePath":"styles.css","content":":root{--inline-code-bg-light: rgb(var(--gray-200) / 0.92);--inline-code-bg-dark: rgb(255 255 255 / 0.08)}.prose :not(pre)>code{background-color:var(--inline-code-bg-light)!important}.dark .prose :not(pre)>code{background-color:var(--inline-code-bg-dark)!important}@media (min-width: 1536px){#navbar>.max-w-8xl,[class*=\"peer-[.is-not-custom]:peer-[.is-not-center]:max-w-8xl\"]{width:100%!important;max-width:none!important}}#navigation-items{display:flex;flex-direction:column}#navigation-items>ul:not(.sidebar-group){order:1;margin-top:1.5rem}.crdb-metrics-table table{table-layout:fixed!important;width:100%!important;min-width:0!important;max-width:100%!important;border-collapse:collapse}.crdb-metrics-table table td,.crdb-metrics-table table th{min-width:0!important;overflow-wrap:anywhere;word-break:break-word}.crdb-fixed-table table{table-layout:fixed!important;width:100%!important;min-width:0!important;max-width:100%!important;border-collapse:collapse}.crdb-fixed-table table td,.crdb-fixed-table table th{min-width:0!important;overflow-wrap:anywhere;word-break:break-word}.bg-cover{background-size:cover;background-repeat:no-repeat;background-position:center center}.bg-cover__bg-3-1{background-image:url(\"https://cockroach-labs-docs.imgix.net/bg-3-1.png?auto=format,compress\u0026w=1200\u0026q=40\")}.home-header{border-radius:0.5rem;margin-bottom:2rem!important;padding:2rem}.card{border:1px solid #e5e7eb;border-radius:0.75rem;background-color:white}.dark .card{background-color:#0d1117;border-color:rgba(255, 255, 255, 0.1)}.card-link{text-decoration:none!important;overflow:hidden}.card-link:hover{outline:1px solid rgba(105, 51, 255, 0.55);outline-offset:-1px}.card-link,.card-link:hover{transform:none!important;box-shadow:none!important}.card-link a,.card-link a:hover,.card-link h3,.card-link h3:hover,.card-link p,.card-link p:hover{border:0!important;text-decoration:none!important;transform:none!important}.card-link a{display:block;width:100%}.card-link h3{font-size:1rem!important;font-weight:600!important}.card-body{padding:1.5rem}.landing-column-title{margin-bottom:1rem}.overline{text-transform:uppercase;letter-spacing:0.05em}.btn-redirect{display:inline-flex;align-items:center;gap:0.5rem;padding:0.75rem 1.5rem;border:2px solid #e5e7eb;border-radius:0.5rem;text-decoration:none;transition:border-color 0.2s}.btn-redirect:hover{border-color:#6933ff}.btn-block{display:flex;width:100%;justify-content:center}.dark .btn-redirect{border-color:rgba(255, 255, 255, 0.1)}.article-section-title{font-size:1.25rem!important}.article-lists h3{font-size:0.875rem!important;font-weight:600!important;text-transform:uppercase;letter-spacing:0.05em;color:#6b7280!important}.dark .article-lists h3{color:#9ca3af!important}.article-lists ul{font-size:0.875rem}.shadow{box-shadow:0 0.5rem 1rem rgba(0, 0, 0, 0.15)}.bg-dark-wing{background-color:#152849;border-radius:0.5rem}.text-ice-temple{color:#1bf8ec!important;display:inline-flex;align-items:center;gap:0.375rem}.text-ice-temple img{display:inline-block;margin:0}.bg-dark-wing h2{font-size:clamp(1.25rem, 1rem + 1.5vw, 1.75rem)!important}@media (max-width: 576px){.card-body.bg-dark-wing{padding:1.25rem!important}}.text-decoration-none{text-decoration:none!important}.text-muted{color:#6b7280!important}.card-link .card-desc{font-size:0.9375rem!important;font-weight:400!important;line-height:1.5!important;text-align:left!important;color:#4b5563!important;width:100%;margin-top:0.5rem}.dark .card-link .card-desc{color:#9ca3af!important}.report-tag{display:inline-block;padding:0.25rem 0.75rem;border-radius:0.25rem;background-color:rgba(84, 42, 189, 0.08);color:#542abd}.dark .report-tag{background-color:rgba(84, 42, 189, 0.3);color:#b39dff}.resilience-report-img{background-image:url(\"/images/state-resilience.png\");background-size:cover;background-position:center;min-height:150px;border-radius:0.5rem}.row{display:flex!important;flex-wrap:wrap;margin-left:-0.75rem;margin-right:-0.75rem}.display-flex{display:flex!important}.col-lg-4{flex:0 0 auto;width:100%;padding-left:0.75rem;padding-right:0.75rem}@media (min-width: 992px){.col-lg-4{width:33.333333%!important}}.col-lg-3,.col-sm-6,.col-xs-12{flex:0 0 auto;width:100%!important;padding-left:0.75rem;padding-right:0.75rem}@media (min-width: 992px){.col-lg-3{width:25%!important}}@media (min-width: 576px){.col-sm-6{width:50%!important}}.col-12{width:100%!important}.col-lg-12{width:100%;padding-left:0.75rem;padding-right:0.75rem}@media (min-width: 992px){.col-lg-12{width:100%!important}}.col-md-4,.col-md-8{flex:0 0 auto;width:100%;padding-left:0.75rem;padding-right:0.75rem}@media (min-width: 768px){.col-md-4{width:33.333333%!important}.col-md-8{width:66.666667%!important}}.h-100{height:100%}.d-flex{display:flex}.flex-column{flex-direction:column}.mb-3{margin-bottom:1rem!important}.mb-5{margin-bottom:3rem!important}.pb-5{padding-bottom:3rem!important}.mb-xl-5{margin-bottom:3rem!important}.mt-auto{margin-top:auto!important}.mt-0{margin-top:0!important}.mt-2{margin-top:0.5rem!important}.mt-3{margin-top:1rem!important}.mt-5:not(.code-block){margin-top:3rem!important}.code-block.mb-8{margin-bottom:calc(var(--spacing) * 5)}.pt-5{padding-top:3rem!important}.m-0{margin:0!important}.ml-2{margin-left:0.5rem!important}.mb-0{margin-bottom:0!important}.mb-2{margin-bottom:0.5rem!important}.mb-4{margin-bottom:1.5rem!important}.p-2{padding:0.5rem!important}.p-3{padding:1rem!important}.p-4{padding:1.5rem!important}.pb-3{padding-bottom:1rem!important}.pb-4{padding-bottom:1.5rem!important}.ml-1{margin-left:0.25rem!important}.mr-auto{margin-right:auto!important}.justify-content-center{justify-content:center!important}.align-items-center{align-items:center!important}@media (min-width: 1200px){.p-xl-5{padding:3rem!important}}.mx-0{margin-left:0!important;margin-right:0!important}.text-center{text-align:center}.text-white{color:white!important}.text-black{color:black!important}.dark .text-black{color:white!important}.container{width:100%;max-width:1200px;margin-left:auto;margin-right:auto;padding-left:1rem;padding-right:1rem}.card-header-overlap-text{position:relative}@media (min-width: 768px){.p-md-5{padding:3rem!important}}@media (min-width: 992px){.d-lg-flex{display:flex!important}.mb-lg-0{margin-bottom:0!important}}.prose table{border-collapse:collapse!important}.prose table th,.prose table td{border:1px solid rgb(var(--gray-200))!important}.dark .prose table th,.dark .prose table td{border-color:rgb(var(--gray-700) / 0.5)!important}.prose table th{padding:0.571429em;font-weight:600;vertical-align:bottom;color:var(--tw-prose-headings);text-align:left}.prose table th.center-align{text-align:center}.prose table td{padding:0.571429em;vertical-align:baseline}[data-component-part=\"accordion-description\"]{font-size:0.875rem!important}.accordion.mb-3{margin-bottom:0.25rem!important}@media (max-width: 991.98px){[id^=\"kapa-widget-container\"] button{width:36px!important;height:36px!important;min-width:36px!important;padding:0!important;font-size:0!important}[id^=\"kapa-widget-container\"] button svg{width:18px!important;height:18px!important}[id^=\"kapa-widget-container\"] button span{display:none!important}}table.crdb-fixed-table{table-layout:fixed!important;min-width:0!important;width:100%}table.crdb-fixed-table td,table.crdb-fixed-table th{min-width:0!important;overflow-wrap:break-word;word-break:normal}.sql-grammar svg .line{fill:none;stroke:#262626}.sql-grammar svg .bold-line{stroke:#0A0A0A;shape-rendering:crispEdges;stroke-width:2}.sql-grammar svg .thin-line{stroke:#0F0F0F;shape-rendering:crispEdges}.sql-grammar svg .filled{fill:#262626;stroke:none}.sql-grammar svg text.terminal{font-family:Verdana, Sans-serif;font-size:12px;fill:#0A0A0A;font-weight:bold}.sql-grammar svg text.nonterminal{font-family:Verdana, Sans-serif;font-size:12px;fill:#0055FF}.sql-grammar svg text.regexp{font-family:Verdana, Sans-serif;font-size:12px;fill:#0F0F0F}.sql-grammar svg rect,.sql-grammar svg circle,.sql-grammar svg polygon{fill:#262626;stroke:#262626}.sql-grammar svg rect.terminal{fill:#ffffff;stroke:#262626}.sql-grammar svg rect.nonterminal{fill:#FFFFFF;stroke:#262626}.sql-grammar svg rect.text{fill:none;stroke:none}.sql-grammar svg polygon.regexp{fill:#FFFFFF;stroke:#262626}.sql-grammar svg{background-color:#ffffff}.sql-grammar a[name]::before{content:'';display:block;height:80px;margin:-80px 0 0}.sql-grammar a[name]:focus{outline:0}pre[language=\"sql\"][data-crdb-prompt-stripped] code::before{content:\"> \";color:#94e2d5;user-select:none}.mark-yes{color:#008a5e;font-weight:600}.dark .mark-yes{color:#3ddc97}"},{"filePath":"collapse-nav.css","content":"html:not(.crl-nav-off) [data-layout-item=\"sidebar\"] li[data-title]:not([data-active]):not([data-crl-keep])>button+ul,html:not(.crl-nav-off) [data-layout-item=\"mobile-nav\"] li[data-title]:not([data-active]):not([data-crl-keep])>button+ul{display:none}html:not(.crl-nav-off) [data-layout-item=\"sidebar\"] li[data-title]:not([data-active]):not([data-crl-keep])>button svg,html:not(.crl-nav-off) [data-layout-item=\"mobile-nav\"] li[data-title]:not([data-active]):not([data-crl-keep])>button svg{rotate:none!important;transform:none!important}"}],"page":{"pagePath":"docs/v23.2/cursors","slug":"/docs/v23.2/cursors","pageMetadata":{"title":"Cursors","old_description":"Paginate results from queries against your cluster using SQL cursors","canonical":"https://docs.cockroachlabs.com/docs/stable/cursors","description":null,"href":"/docs/v23.2/cursors"},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];const InternalLink=({version,path=``,children,...props})=>{const _components={a:`a`,..._provideComponents()};let detectedVersion=version||`stable`;if(typeof window!==`undefined`\u0026\u0026!version){const match=window.location.pathname.match(/\\/docs\\/([^/]+)/);if(match){detectedVersion=match[1]}}const normalizedPath=path.startsWith(`/`)?path.slice(1):path;return _jsx(_components.a,{href:`/docs/${detectedVersion}/${normalizedPath}`,...props,children})};function _createMdxContent(props){const _components={code:`code`,em:`em`,li:`li`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,OptimizedImage,Tip,_MdxComponentBoundary}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!OptimizedImage)_missingMdxReference(`OptimizedImage`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!_MdxComponentBoundary)_missingMdxReference(`_MdxComponentBoundary`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`A cursor is a placeholder into a selection query that allows you to iterate over subsets of the rows returned by that query.`}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`This document describes cursor usage within SQL transactions. For information about using cursors in PL/pgSQL functions and procedures, see `,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`plpgsql#declare-cursor-variables`,children:`PL/pgSQL`})}),`.`]})}),`\n`,_jsxs(_components.p,{children:[`Cursors differ from `,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`pagination`,children:`keyset pagination`})}),` and `,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsxs(InternalLink,{path:`limit-offset`,children:[_jsx(_components.code,{children:`LIMIT`}),`/`,_jsx(_components.code,{children:`OFFSET`})]})}),` in that:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`Each cursor is a stateful SQL object that is referred to by a unique name.`}),`\n`,_jsxs(_components.li,{children:[`Each cursor requires holding open its own dedicated (read-only) `,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`transactions`,children:`transaction`})}),`.`]}),`\n`,_jsx(_components.li,{children:`Each cursor operates on a snapshot of the database at the moment that cursor is opened.`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`synopsis`,children:`Synopsis`}),`\n`,_jsx(OptimizedImage,{src:`https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/v23.2/declare_cursor.svg?fit=max\u0026auto=format\u0026n=M6E8QStE4G5ISd4O\u0026q=85\u0026s=0e668a451daeb25fc7b5832ac1e75d24`,alt:`declare_cursor syntax diagram`,style:{maxWidth:`100%`,overflowX:`auto`},\"data-og-width\":`697`,width:`697`,\"data-og-height\":`103`,height:`103`,\"data-path\":`images/sql-diagrams/v23.2/declare_cursor.svg`,\"data-optimize\":`true`,\"data-opv\":`3`,srcset:`https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/v23.2/declare_cursor.svg?w=280\u0026fit=max\u0026auto=format\u0026n=M6E8QStE4G5ISd4O\u0026q=85\u0026s=33ada2370b48fedd5c65ca8d417d8fc7 280w, https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/v23.2/declare_cursor.svg?w=560\u0026fit=max\u0026auto=format\u0026n=M6E8QStE4G5ISd4O\u0026q=85\u0026s=b5e3cf7628ec3b1586d245807984caa6 560w, https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/v23.2/declare_cursor.svg?w=840\u0026fit=max\u0026auto=format\u0026n=M6E8QStE4G5ISd4O\u0026q=85\u0026s=3fe2df44758f07207c14f3cc638bba8b 840w, https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/v23.2/declare_cursor.svg?w=1100\u0026fit=max\u0026auto=format\u0026n=M6E8QStE4G5ISd4O\u0026q=85\u0026s=d1198ee721325824c8f77a5ac97ea77d 1100w, https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/v23.2/declare_cursor.svg?w=1650\u0026fit=max\u0026auto=format\u0026n=M6E8QStE4G5ISd4O\u0026q=85\u0026s=0f4d7f12d3fea9db83e272ad394dfba7 1650w, https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/v23.2/declare_cursor.svg?w=2500\u0026fit=max\u0026auto=format\u0026n=M6E8QStE4G5ISd4O\u0026q=85\u0026s=356b6c02d75584ec515910e735b8f992 2500w`}),`\n`,_jsx(OptimizedImage,{src:`https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/fetch_cursor.svg?fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=b09345a54f3ef7d24124c98d0a1d240e`,alt:`fetch_cursor syntax diagram`,style:{maxWidth:`100%`,overflowX:`auto`},\"data-og-width\":`337`,width:`337`,\"data-og-height\":`37`,height:`37`,\"data-path\":`images/sql-diagrams/common/fetch_cursor.svg`,\"data-optimize\":`true`,\"data-opv\":`3`,srcset:`https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/fetch_cursor.svg?w=280\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=926984eee836a7fcca7409898a767b6f 280w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/fetch_cursor.svg?w=560\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=5ec1802b41e46d1b50675b29076a424c 560w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/fetch_cursor.svg?w=840\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=b16a143e2ff525b227c0441d0b7e5888 840w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/fetch_cursor.svg?w=1100\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=52f5e08b162eab1bd81d3e8e778aaa61 1100w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/fetch_cursor.svg?w=1650\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=d0bec4a51263b05679f96bed17894f9d 1650w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/fetch_cursor.svg?w=2500\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=38d74a897d914d2fee148af12be0219d 2500w`}),`\n`,_jsx(OptimizedImage,{src:`https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/close_cursor.svg?fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=42c492ff8f16e3ad4bd50bde3ba1d5f8`,alt:`close_cursor syntax diagram`,style:{maxWidth:`100%`,overflowX:`auto`},\"data-og-width\":`285`,width:`285`,\"data-og-height\":`81`,height:`81`,\"data-path\":`images/sql-diagrams/common/close_cursor.svg`,\"data-optimize\":`true`,\"data-opv\":`3`,srcset:`https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/close_cursor.svg?w=280\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=f94eab5a2236fedb13e8536bff9a97ca 280w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/close_cursor.svg?w=560\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=911745c59175f5199ab83fc8427cb0e4 560w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/close_cursor.svg?w=840\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=60991031dc57fe5c4fc321c7fcff3ab8 840w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/close_cursor.svg?w=1100\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=9ba6e4ac1217a9deae08f57df0b9e60f 1100w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/close_cursor.svg?w=1650\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=57b2eb2684ea85d72859ed054fde7115 1650w, https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/close_cursor.svg?w=2500\u0026fit=max\u0026auto=format\u0026n=UZNSFbmU2EwEm6G5\u0026q=85\u0026s=7940c578d5a9bd7150075dbd20a8da01 2500w`}),`\n`,_jsx(_components.p,{children:`Cursors are declared and used with the following keywords:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`sql-grammar`,children:_jsx(_components.code,{children:`DECLARE`})})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`sql-grammar`,children:_jsx(_components.code,{children:`FETCH`})})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`sql-grammar`,children:_jsx(_components.code,{children:`CLOSE`})})}),`\n`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`examples`,children:`Examples`}),`\n`,_jsxs(_components.p,{children:[`These examples assume the presence of the `,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`movr`,children:`MovR data set`})}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`use-a-cursor`,children:`Use a cursor`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`BEGIN`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`DECLARE`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` rides_cursor `}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`CURSOR`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` FOR`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` SELECT`}),_jsx(_components.span,{style:{color:`#94E2D5`,\"--shiki-dark\":`#94E2D5`},children:` *`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` FROM`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` movr.rides;`})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`FETCH`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` FORWARD `}),_jsx(_components.span,{style:{color:`#FAB387`,\"--shiki-dark\":`#FAB387`},children:`5`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` FROM`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` rides_cursor;`})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`9`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` id | city | vehicle_city | rider_id | vehicle_id | start_address | end_address | start_time | end_time | revenue`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`---------------------------------------+---------------+---------------+--------------------------------------+--------------------------------------+-----------------------------+----------------------------+---------------------+---------------------+----------`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` 8ccccccc-cccc-4000-8000-000000000113 | san francisco | san francisco | 80000000-0000-4000-8000-000000000019 | 77777777-7777-4800-8000-000000000007 | 69313 Jody Tunnel Apt. 17 | 5210 Kim Canyon Suite 84 | 2018-12-22 03:04:05 | 2018-12-22 07:04:05 | 36.00`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` 8d4fdf3b-645a-4000-8000-000000000114 | san francisco | san francisco | 80000000-0000-4000-8000-000000000019 | 88888888-8888-4800-8000-000000000008 | 54797 Lauren Cliffs Apt. 37 | 7425 Matthews Harbors | 2018-12-18 03:04:05 | 2018-12-20 04:04:05 | 45.00`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` 8dd2f1a9-fbe7-4000-8000-000000000115 | san francisco | san francisco | 75c28f5c-28f5-4400-8000-000000000017 | 77777777-7777-4800-8000-000000000007 | 23053 Brown Creek | 15838 Preston Unions | 2018-12-26 03:04:05 | 2018-12-27 15:04:05 | 34.00`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` 55810624-dd2f-4c00-8000-0000000000a7 | seattle | seattle | 570a3d70-a3d7-4c00-8000-000000000011 | 55555555-5555-4400-8000-000000000005 | 78340 Ashley Common Apt. 4 | 19798 Riggs Spring | 2018-12-08 03:04:05 | 2018-12-10 06:04:05 | 13.00`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` 56041893-74bc-4c00-8000-0000000000a8 | seattle | seattle | 570a3d70-a3d7-4c00-8000-000000000011 | 66666666-6666-4800-8000-000000000006 | 6431 Robert Forest | 83655 Michael Cape Apt. 94 | 2018-12-09 03:04:05 | 2018-12-09 14:04:05 | 48.00`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`(5 rows)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`CLOSE`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` rides_cursor;`})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`COMMIT`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`view-all-open-cursors`,children:`View all open cursors`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`SELECT`}),_jsx(_components.span,{style:{color:`#94E2D5`,\"--shiki-dark\":`#94E2D5`},children:` *`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` FROM`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` pg_cursors;`})]}),`\n`]})})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`text`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`text`,children:_jsxs(_components.code,{language:`text`,numberOfLines:`5`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` name | statement | is_holdable | is_binary | is_scrollable | creation_time`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`---------------+---------------------+-------------+-----------+---------------+--------------------------------`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:` rides_cursor | SELECT * FROM rides | f | f | f | 2023-03-30 15:24:37.568054+00`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{children:`(1 row)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{})})]})})}),`\n`,_jsx(`a`,{id:`best-practices`}),`\n`,_jsx(Heading,{level:`2`,id:`limitations`,children:`Limitations`}),`\n`,_jsx(_components.p,{children:`CockroachDB implements SQL cursor support with the following limitations:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`DECLARE`}),` only supports forward cursors. Reverse cursors created with `,_jsx(_components.code,{children:`DECLARE SCROLL`}),` are not supported.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`FETCH`}),` supports forward, relative, and absolute variants, but only for forward cursors.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`BINARY CURSOR`}),`, which returns data in the Postgres binary format, is not supported.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`WITH HOLD`}),`, which allows keeping a cursor open for longer than a transaction by writing its results into a buffer, is accepted as valid syntax within a single transaction but is not supported. It acts as a no-op and does not actually perform the function of `,_jsx(_components.code,{children:`WITH HOLD`}),`, which is to make the cursor live outside its parent transaction. Instead, if you are using `,_jsx(_components.code,{children:`WITH HOLD`}),`, you will be forced to close that cursor within the transaction it was created in.`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_components.p,{children:`This syntax is accepted (but does not have any effect):`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`BEGIN`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`DECLARE`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` test_cur `}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`CURSOR`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` WITH`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` HOLD `}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`FOR`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` SELECT`}),_jsx(_components.span,{style:{color:`#94E2D5`,\"--shiki-dark\":`#94E2D5`},children:` *`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` FROM`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` foo `}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`ORDER BY`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` bar;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`CLOSE`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` test_cur;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`COMMIT`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:`;`})]}),`\n`]})})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_components.p,{children:`This syntax is not accepted, and will result in an error:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`sql`,children:_jsx(_components.pre,{className:`shiki shiki-themes catppuccin-mocha catppuccin-mocha`,style:{backgroundColor:`#1e1e2e`,\"--shiki-dark-bg\":`#1e1e2e`,color:`#cdd6f4`,\"--shiki-dark\":`#cdd6f4`},language:`sql`,children:_jsxs(_components.code,{language:`sql`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`BEGIN`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`DECLARE`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` test_cur `}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`CURSOR`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` WITH`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` HOLD `}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`FOR`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` SELECT`}),_jsx(_components.span,{style:{color:`#94E2D5`,\"--shiki-dark\":`#94E2D5`},children:` *`}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:` FROM`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` foo `}),_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`ORDER BY`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:` bar;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CBA6F7`,\"--shiki-dark\":`#CBA6F7`},children:`COMMIT`}),_jsx(_components.span,{style:{color:`#CDD6F4`,\"--shiki-dark\":`#CDD6F4`},children:`; `}),_jsx(_components.span,{style:{color:`#9399B2`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#9399B2`,\"--shiki-dark-font-style\":`italic`},children:`-- This will fail with an error because CLOSE test_cur was not called inside the transaction.`})]}),`\n`]})})}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`Scrollable cursor (also known as reverse `,_jsx(_components.code,{children:`FETCH`}),`) is not supported.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`select-for-update`,children:_jsx(_components.code,{children:`SELECT... FOR UPDATE`})})}),` with a cursor is not supported.`]}),`\n`,_jsxs(_components.li,{children:[`Respect for `,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsxs(InternalLink,{path:`savepoint`,children:[_jsx(_components.code,{children:`SAVEPOINT`}),`s`]})}),` is not supported. Cursor definitions do not disappear properly if rolled back to a `,_jsx(_components.code,{children:`SAVEPOINT`}),` from before they were created.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`differences-between-cursors-and-keyset-pagination`,children:`Differences between cursors and keyset pagination`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.em,{children:`Cursors`}),` are stateful objects that use more database resources than keyset pagination, since each cursor holds open a transaction. However, they are easier to use, and make it easier to get consistent results without having to write complex queries from your application logic. They do not require that the results be returned in a particular order (that is, you don’t have to include an `,_jsx(_components.code,{children:`ORDER BY`}),` clause), which makes them more flexible.`]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.em,{children:`Keyset pagination`}),` queries are usually much faster than cursors since they order by indexed columns. However, in order to get that performance they require that you return results in some defined order that can be calculated by your application’s queries. Because that ordering involves calculating the start/end point of pages of results based on an indexed key, they require more care to write correctly.`]}),`\n`,_jsx(Heading,{level:`2`,id:`see-also`,children:`See also`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsx(InternalLink,{path:`pagination`,children:`Keyset pagination`})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_MdxComponentBoundary,{name:`InternalLink`,children:_jsxs(InternalLink,{path:`limit-offset`,children:[_jsx(_components.code,{children:`LIMIT`}),`/`,_jsx(_components.code,{children:`OFFSET`})]})}),`\n`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{InternalLink,default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}},"config":{},"pageMetadata":{"title":"Cursors","old_description":"Paginate results from queries against your cluster using SQL cursors","canonical":"https://docs.cockroachlabs.com/docs/stable/cursors","description":null,"href":"/docs/v23.2/cursors"}}},"mdxSourceWithNoJs":null,"noJsSplices":[[148,586,")=>null;function _cr"]]},"mdxExtracts":{"tableOfContents":[{"title":"Synopsis","slug":"synopsis","depth":2,"children":[]},{"title":"Examples","slug":"examples","depth":2,"children":[{"title":"Use a cursor","slug":"use-a-cursor","depth":3,"children":[]},{"title":"View all open cursors","slug":"view-all-open-cursors","depth":3,"children":[]}]},{"title":"Limitations","slug":"limitations","depth":2,"children":[]},{"title":"Differences between cursors and keyset pagination","slug":"differences-between-cursors-and-keyset-pagination","depth":2,"children":[]},{"title":"See also","slug":"see-also","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/cockroachlabs/4695317e415d4eba/kapa.js","/_mintlify/custom/cockroachlabs/40fb45a3cfe42c92/copy-code-prompt.js","/_mintlify/custom/cockroachlabs/3f343c9e8c40397a/collapse-nav.js"],"subdomain":"cockroachlabs","siteName":"CockroachDB","title":"Cursors - CockroachDB","navMaps":{"firstHrefInVersion":{"v26.4":{"href":"/docs/stable/cursors","matchLevel":1},"v26.3":{"href":"/docs/v26.3/cursors","matchLevel":1,"canonicalOverride":true},"v26.2":{"href":"/docs/v26.2/cursors","matchLevel":1,"canonicalOverride":true},"v26.1":{"href":"/docs/v26.1/cursors","matchLevel":1,"canonicalOverride":true},"v25.4":{"href":"/docs/v25.4/cursors","matchLevel":1,"canonicalOverride":true},"v25.3":{"href":"/docs/v25.3/cursors","matchLevel":1,"canonicalOverride":true},"v25.2":{"href":"/docs/v25.2/cursors","matchLevel":1,"canonicalOverride":true},"v25.1":{"href":"/docs/v25.1/cursors","matchLevel":1,"canonicalOverride":true},"v24.3":{"href":"/docs/v24.3/cursors","matchLevel":1,"canonicalOverride":true},"v24.1":{"href":"/docs/v24.1/cursors","matchLevel":1,"canonicalOverride":true},"v23.2":{"href":"/docs/v23.2/cursors","matchLevel":0},"v23.1":{"href":"/docs/v23.1/cursors","matchLevel":1,"canonicalOverride":true}},"firstHrefInLanguage":{}},"lastModified":"2026-11-06T15:56:01.315Z","originalFileLocation":"docs/v23.2/cursors.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"light\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"application-name\" content=\"CockroachDB\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Cursors - CockroachDB\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"CockroachDB\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.cockroachlabs.com/docs/stable/cursors\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://cockroachlabs.mintlify.site/_mintlify/api/og/v2?division=Syntax\u0026amp;title=Cursors\u0026amp;theme=7628870a42004e67b5b3df3d\u0026amp;signature=c1f7018606c0aa3e463a51faa2865448c632fc1e9fcc5535f8d817cab1300572\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Cursors - CockroachDB\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://cockroachlabs.mintlify.site/_mintlify/api/og/v2?division=Syntax\u0026amp;title=Cursors\u0026amp;theme=7628870a42004e67b5b3df3d\u0026amp;signature=c1f7018606c0aa3e463a51faa2865448c632fc1e9fcc5535f8d817cab1300572\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/cockroachlabs/c9BlkJ0WBi2Ma7w-/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"CockroachDB\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#9059FF\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.cockroachlabs.com/docs/stable/cursors\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/v23.2/cursors.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.cockroachlabs.com/#organization\",\"name\":\"CockroachDB\",\"url\":\"https://docs.cockroachlabs.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/cockroachlabs/4WvUnbVuGZfqM4kW/images/CockroachLabs_Wordmark_Black.png?fit=max\u0026auto=format\u0026n=4WvUnbVuGZfqM4kW\u0026q=85\u0026s=54ccae625c9986bf1df8ddc7b2c571f0\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.cockroachlabs.com#website\",\"name\":\"CockroachDB\",\"url\":\"https://docs.cockroachlabs.com\",\"publisher\":{\"@id\":\"https://docs.cockroachlabs.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.cockroachlabs.com/docs/stable/cursors#webpage\",\"url\":\"https://docs.cockroachlabs.com/docs/stable/cursors\",\"name\":\"Cursors\",\"dateModified\":\"2026-11-06T15:56:01.315Z\",\"isPartOf\":{\"@id\":\"https://docs.cockroachlabs.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.cockroachlabs.com/docs/stable/cursors#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.cockroachlabs.com/docs/stable/cursors#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Syntax\",\"item\":\"https://docs.cockroachlabs.com/docs/v23.2/keywords-and-identifiers\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Cursors\",\"item\":\"https://docs.cockroachlabs.com/docs/stable/cursors\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.cockroachlabs.com/docs/stable/cursors#article\",\"headline\":\"Cursors\",\"name\":\"Cursors\",\"url\":\"https://docs.cockroachlabs.com/docs/stable/cursors\",\"mainEntityOfPage\":{\"@id\":\"https://docs.cockroachlabs.com/docs/stable/cursors#webpage\"},\"dateModified\":\"2026-11-06T15:56:01.315Z\",\"publisher\":{\"@id\":\"https://docs.cockroachlabs.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.cockroachlabs.com#website\"}}]}\u003c/script>","siteName":"CockroachDB","nav":{"global":{"anchors":[{"anchor":"University","icon":"graduation-cap","href":"https://learn.cockroachlabs.com/"}]},"products":[{"product":"Cockroach Continuum Cloud","icon":"https://mintlify.s3.us-west-1.amazonaws.com/cockroachlabs/images/continuum/cockroachlabs-symbol.svg","description":"The agentic database cloud","pages":[{"title":"Cockroach Continuum Cloud","href":"/docs/continuum"}]},{"product":"CockroachDB","icon":"database","description":"Distributed SQL database","versions":[{"version":"v26.4","default":true,"tag":"Stable","pages":[{"title":"v26.4","href":"/docs/stable/cursors"}]},{"version":"v26.3","pages":[{"title":"v26.3","href":"/docs/v26.3/cursors"}]},{"version":"v26.2","pages":[{"title":"v26.2","href":"/docs/v26.2/cursors"}]},{"version":"v26.1","pages":[{"title":"v26.1","href":"/docs/v26.1/cursors"}]},{"version":"v25.4","tag":"LTS","pages":[{"title":"v25.4","href":"/docs/v25.4/cursors"}]},{"version":"v25.3","tag":"Unsupported","pages":[{"title":"v25.3","href":"/docs/v25.3/cursors"}]},{"version":"v25.2","tag":"LTS","pages":[{"title":"v25.2","href":"/docs/v25.2/cursors"}]},{"version":"v25.1","tag":"Unsupported","pages":[{"title":"v25.1","href":"/docs/v25.1/cursors"}]},{"version":"v24.3","tag":"LTS","pages":[{"title":"v24.3","href":"/docs/v24.3/cursors"}]},{"version":"v24.1","tag":"LTS","pages":[{"title":"v24.1","href":"/docs/v24.1/cursors"}]},{"version":"v23.2","tag":"LTS","tabs":[{"tab":"Docs","icon":"book-open","pages":[{"title":"Docs","href":"/docs/v23.2"}]},{"tab":"Migrate","icon":"arrow-right-arrow-left","pages":[{"title":"Migrate","href":"/docs/molt/migration-overview"}]},{"tab":"SQL","icon":"code","pages":[{"group":"Statements","pages":[{"title":"SQL Statements","sidebarTitle":"Overview","href":"/docs/v23.2/sql-statements"},{"title":"ALTER BACKUP","sidebarTitle":"ALTER BACKUP","href":"/docs/v23.2/alter-backup"},{"title":"ALTER BACKUP SCHEDULE","sidebarTitle":"ALTER BACKUP SCHEDULE","href":"/docs/v23.2/alter-backup-schedule"},{"title":"ALTER CHANGEFEED","sidebarTitle":"ALTER CHANGEFEED","href":"/docs/v23.2/alter-changefeed"},{"title":"ALTER DATABASE","sidebarTitle":"ALTER DATABASE","href":"/docs/v23.2/alter-database"},{"title":"ALTER DEFAULT PRIVILEGES","sidebarTitle":"ALTER DEFAULT PRIVILEGES","href":"/docs/v23.2/alter-default-privileges"},{"title":"ALTER FUNCTION","sidebarTitle":"ALTER FUNCTION","href":"/docs/v23.2/alter-function"},{"title":"ALTER INDEX","sidebarTitle":"ALTER INDEX","href":"/docs/v23.2/alter-index"},{"title":"ALTER PARTITION","sidebarTitle":"ALTER PARTITION","href":"/docs/v23.2/alter-partition"},{"title":"ALTER PROCEDURE","sidebarTitle":"ALTER PROCEDURE","href":"/docs/v23.2/alter-procedure"},{"title":"ALTER RANGE","sidebarTitle":"ALTER RANGE","href":"/docs/v23.2/alter-range"},{"title":"ALTER ROLE","sidebarTitle":"ALTER ROLE","href":"/docs/v23.2/alter-role"},{"title":"ALTER SCHEMA","sidebarTitle":"ALTER SCHEMA","href":"/docs/v23.2/alter-schema"},{"title":"ALTER SEQUENCE","sidebarTitle":"ALTER SEQUENCE","href":"/docs/v23.2/alter-sequence"},{"title":"ALTER TABLE","sidebarTitle":"ALTER TABLE","href":"/docs/v23.2/alter-table"},{"title":"ALTER TYPE","sidebarTitle":"ALTER TYPE","href":"/docs/v23.2/alter-type"},{"title":"ALTER USER","sidebarTitle":"ALTER USER","href":"/docs/v23.2/alter-user"},{"title":"ALTER VIEW","sidebarTitle":"ALTER VIEW","href":"/docs/v23.2/alter-view"},{"title":"ALTER VIRTUAL CLUSTER","sidebarTitle":"ALTER VIRTUAL CLUSTER","href":"/docs/v23.2/alter-virtual-cluster"},{"title":"BACKUP","sidebarTitle":"BACKUP","href":"/docs/v23.2/backup"},{"title":"BEGIN","sidebarTitle":"BEGIN","href":"/docs/v23.2/begin-transaction"},{"title":"CALL","sidebarTitle":"CALL","href":"/docs/v23.2/call"},{"title":"CANCEL JOB","sidebarTitle":"CANCEL JOB","href":"/docs/v23.2/cancel-job"},{"title":"CANCEL QUERY","sidebarTitle":"CANCEL QUERY","href":"/docs/v23.2/cancel-query"},{"title":"CANCEL SESSION","sidebarTitle":"CANCEL SESSION","href":"/docs/v23.2/cancel-session"},{"title":"COMMENT ON","sidebarTitle":"COMMENT ON","href":"/docs/v23.2/comment-on"},{"title":"COMMIT","sidebarTitle":"COMMIT","href":"/docs/v23.2/commit-transaction"},{"title":"COPY","sidebarTitle":"COPY","href":"/docs/v23.2/copy"},{"title":"CREATE CHANGEFEED","sidebarTitle":"CREATE CHANGEFEED","href":"/docs/v23.2/create-changefeed"},{"title":"CREATE DATABASE","sidebarTitle":"CREATE DATABASE","href":"/docs/v23.2/create-database"},{"title":"CREATE EXTERNAL CONNECTION","sidebarTitle":"CREATE EXTERNAL CONNECTION","href":"/docs/v23.2/create-external-connection"},{"title":"CREATE FUNCTION","sidebarTitle":"CREATE FUNCTION","href":"/docs/v23.2/create-function"},{"title":"CREATE INDEX","sidebarTitle":"CREATE INDEX","href":"/docs/v23.2/create-index"},{"title":"CREATE PROCEDURE","sidebarTitle":"CREATE PROCEDURE","href":"/docs/v23.2/create-procedure"},{"title":"CREATE ROLE","sidebarTitle":"CREATE ROLE","href":"/docs/v23.2/create-role"},{"title":"CREATE SCHEDULE FOR BACKUP","sidebarTitle":"CREATE SCHEDULE FOR BACKUP","href":"/docs/v23.2/create-schedule-for-backup"},{"title":"CREATE SCHEDULE FOR CHANGEFEED","sidebarTitle":"CREATE SCHEDULE FOR CHANGEFEED","href":"/docs/v23.2/create-schedule-for-changefeed"},{"title":"CREATE SCHEMA","sidebarTitle":"CREATE SCHEMA","href":"/docs/v23.2/create-schema"},{"title":"CREATE SEQUENCE","sidebarTitle":"CREATE SEQUENCE","href":"/docs/v23.2/create-sequence"},{"title":"CREATE STATISTICS","sidebarTitle":"CREATE STATISTICS","href":"/docs/v23.2/create-statistics"},{"title":"CREATE TABLE","sidebarTitle":"CREATE TABLE","href":"/docs/v23.2/create-table"},{"title":"CREATE TABLE AS","sidebarTitle":"CREATE TABLE AS","href":"/docs/v23.2/create-table-as"},{"title":"CREATE TYPE","sidebarTitle":"CREATE TYPE","href":"/docs/v23.2/create-type"},{"title":"CREATE USER","sidebarTitle":"CREATE USER","href":"/docs/v23.2/create-user"},{"title":"CREATE VIEW","sidebarTitle":"CREATE VIEW","href":"/docs/v23.2/create-view"},{"title":"CREATE VIRTUAL CLUSTER","sidebarTitle":"CREATE VIRTUAL CLUSTER","href":"/docs/v23.2/create-virtual-cluster"},{"title":"DELETE","sidebarTitle":"DELETE","href":"/docs/v23.2/delete"},{"title":"DROP DATABASE","sidebarTitle":"DROP DATABASE","href":"/docs/v23.2/drop-database"},{"title":"DROP EXTERNAL CONNECTION","sidebarTitle":"DROP EXTERNAL CONNECTION","href":"/docs/v23.2/drop-external-connection"},{"title":"DROP FUNCTION","sidebarTitle":"DROP FUNCTION","href":"/docs/v23.2/drop-function"},{"title":"DROP OWNED BY","sidebarTitle":"DROP OWNED BY","href":"/docs/v23.2/drop-owned-by"},{"title":"DROP TYPE","sidebarTitle":"DROP TYPE","href":"/docs/v23.2/drop-type"},{"title":"DROP INDEX","sidebarTitle":"DROP INDEX","href":"/docs/v23.2/drop-index"},{"title":"DROP PROCEDURE","sidebarTitle":"DROP PROCEDURE","href":"/docs/v23.2/drop-procedure"},{"title":"DROP ROLE","sidebarTitle":"DROP ROLE","href":"/docs/v23.2/drop-role"},{"title":"DROP SCHEDULES","sidebarTitle":"DROP SCHEDULES","href":"/docs/v23.2/drop-schedules"},{"title":"DROP SCHEMA","sidebarTitle":"DROP SCHEMA","href":"/docs/v23.2/drop-schema"},{"title":"DROP SEQUENCE","sidebarTitle":"DROP SEQUENCE","href":"/docs/v23.2/drop-sequence"},{"title":"DROP TABLE","sidebarTitle":"DROP TABLE","href":"/docs/v23.2/drop-table"},{"title":"DROP USER","sidebarTitle":"DROP USER","href":"/docs/v23.2/drop-user"},{"title":"DROP VIEW","sidebarTitle":"DROP VIEW","href":"/docs/v23.2/drop-view"},{"title":"DROP VIRTUAL CLUSTER","sidebarTitle":"DROP VIRTUAL CLUSTER","href":"/docs/v23.2/drop-virtual-cluster"},{"title":"EXPERIMENTAL CHANGEFEED FOR","sidebarTitle":"EXPERIMENTAL CHANGEFEED FOR","href":"/docs/v23.2/changefeed-for"},{"title":"EXPLAIN","sidebarTitle":"EXPLAIN","href":"/docs/v23.2/explain"},{"title":"EXPLAIN ANALYZE","sidebarTitle":"EXPLAIN ANALYZE","href":"/docs/v23.2/explain-analyze"},{"title":"EXPORT","sidebarTitle":"EXPORT","href":"/docs/v23.2/export"},{"title":"GRANT","sidebarTitle":"GRANT","href":"/docs/v23.2/grant"},{"title":"IMPORT INTO","sidebarTitle":"IMPORT INTO","href":"/docs/v23.2/import-into"},{"title":"INSERT","sidebarTitle":"INSERT","href":"/docs/v23.2/insert"},{"title":"JOIN expressions","sidebarTitle":"JOIN","href":"/docs/v23.2/joins"},{"title":"Limit Query Results","sidebarTitle":"LIMIT/OFFSET","href":"/docs/v23.2/limit-offset"},{"title":"ORDER BY","sidebarTitle":"ORDER BY","href":"/docs/v23.2/order-by"},{"title":"PAUSE JOB","sidebarTitle":"PAUSE JOB","href":"/docs/v23.2/pause-job"},{"title":"PAUSE SCHEDULES","sidebarTitle":"PAUSE SCHEDULES","href":"/docs/v23.2/pause-schedules"},{"title":"REASSIGN OWNED","sidebarTitle":"REASSIGN OWNED","href":"/docs/v23.2/reassign-owned"},{"title":"REFRESH","sidebarTitle":"REFRESH","href":"/docs/v23.2/refresh"},{"title":"RELEASE SAVEPOINT","sidebarTitle":"RELEASE SAVEPOINT","href":"/docs/v23.2/release-savepoint"},{"title":"RESET CLUSTER SETTING","sidebarTitle":"RESET CLUSTER SETTING","href":"/docs/v23.2/reset-cluster-setting"},{"title":"RESET {session variable}","sidebarTitle":"RESET {session variable}","href":"/docs/v23.2/reset-vars"},{"title":"RESTORE","sidebarTitle":"RESTORE","href":"/docs/v23.2/restore"},{"title":"RESUME JOB","sidebarTitle":"RESUME JOB","href":"/docs/v23.2/resume-job"},{"title":"RESUME SCHEDULES","sidebarTitle":"RESUME SCHEDULES","href":"/docs/v23.2/resume-schedules"},{"title":"REVOKE","sidebarTitle":"REVOKE","href":"/docs/v23.2/revoke"},{"title":"ROLLBACK","sidebarTitle":"ROLLBACK","href":"/docs/v23.2/rollback-transaction"},{"title":"SAVEPOINT","sidebarTitle":"SAVEPOINT","href":"/docs/v23.2/savepoint"},{"title":"Simple SELECT Clause","sidebarTitle":"SELECT","href":"/docs/v23.2/select-clause"},{"title":"FOR UPDATE and FOR SHARE","sidebarTitle":"FOR UPDATE and FOR SHARE","href":"/docs/v23.2/select-for-update"},{"title":"SET CLUSTER SETTING","sidebarTitle":"SET CLUSTER SETTING","href":"/docs/v23.2/set-cluster-setting"},{"title":"SET {session variable}","sidebarTitle":"SET {session variable}","href":"/docs/v23.2/set-vars"},{"title":"SET TRANSACTION","sidebarTitle":"SET TRANSACTION","href":"/docs/v23.2/set-transaction"},{"title":"SHOW BACKUP","sidebarTitle":"SHOW BACKUP","href":"/docs/v23.2/show-backup"},{"title":"SHOW CLUSTER SETTING","sidebarTitle":"SHOW CLUSTER SETTING","href":"/docs/v23.2/show-cluster-setting"},{"title":"SHOW COLUMNS","sidebarTitle":"SHOW COLUMNS","href":"/docs/v23.2/show-columns"},{"title":"SHOW CONSTRAINTS","sidebarTitle":"SHOW CONSTRAINTS","href":"/docs/v23.2/show-constraints"},{"title":"SHOW CREATE","sidebarTitle":"SHOW CREATE","href":"/docs/v23.2/show-create"},{"title":"SHOW CREATE EXTERNAL CONNECTION","sidebarTitle":"SHOW CREATE EXTERNAL CONNECTION","href":"/docs/v23.2/show-create-external-connection"},{"title":"SHOW CREATE SCHEDULE","sidebarTitle":"SHOW CREATE SCHEDULE","href":"/docs/v23.2/show-create-schedule"},{"title":"SHOW DATABASES","sidebarTitle":"SHOW DATABASES","href":"/docs/v23.2/show-databases"},{"title":"SHOW DEFAULT PRIVILEGES","sidebarTitle":"SHOW DEFAULT PRIVILEGES","href":"/docs/v23.2/show-default-privileges"},{"title":"SHOW ENUMS","sidebarTitle":"SHOW ENUMS","href":"/docs/v23.2/show-enums"},{"title":"SHOW FULL TABLE SCANS","sidebarTitle":"SHOW FULL TABLE SCANS","href":"/docs/v23.2/show-full-table-scans"},{"title":"SHOW GRANTS","sidebarTitle":"SHOW GRANTS","href":"/docs/v23.2/show-grants"},{"title":"SHOW INDEX","sidebarTitle":"SHOW INDEX","href":"/docs/v23.2/show-index"},{"title":"SHOW JOBS","sidebarTitle":"SHOW JOBS","href":"/docs/v23.2/show-jobs"},{"title":"SHOW LOCALITY","sidebarTitle":"SHOW LOCALITY","href":"/docs/v23.2/show-locality"},{"title":"SHOW PARTITIONS","sidebarTitle":"SHOW PARTITIONS","href":"/docs/v23.2/show-partitions"},{"title":"SHOW RANGES","sidebarTitle":"SHOW RANGES","href":"/docs/v23.2/show-ranges"},{"title":"SHOW RANGE FOR ROW","sidebarTitle":"SHOW RANGE FOR ROW","href":"/docs/v23.2/show-range-for-row"},{"title":"SHOW REGIONS","sidebarTitle":"SHOW REGIONS","href":"/docs/v23.2/show-regions"},{"title":"SHOW {session variable}","sidebarTitle":"SHOW {session variable}","href":"/docs/v23.2/show-vars"},{"title":"SHOW SUPER REGIONS","sidebarTitle":"SHOW SUPER REGIONS","href":"/docs/v23.2/show-super-regions"},{"title":"SHOW SYSTEM GRANTS","sidebarTitle":"SHOW SYSTEM GRANTS","href":"/docs/v23.2/show-system-grants"},{"title":"SHOW ROLES","sidebarTitle":"SHOW ROLES","href":"/docs/v23.2/show-roles"},{"title":"SHOW SCHEDULES","sidebarTitle":"SHOW SCHEDULES","href":"/docs/v23.2/show-schedules"},{"title":"SHOW SCHEMAS","sidebarTitle":"SHOW SCHEMAS","href":"/docs/v23.2/show-schemas"},{"title":"SHOW SEQUENCES","sidebarTitle":"SHOW SEQUENCES","href":"/docs/v23.2/show-sequences"},{"title":"SHOW SESSIONS","sidebarTitle":"SHOW SESSIONS","href":"/docs/v23.2/show-sessions"},{"title":"SHOW STATEMENTS","sidebarTitle":"SHOW STATEMENTS","href":"/docs/v23.2/show-statements"},{"title":"SHOW STATISTICS","sidebarTitle":"SHOW STATISTICS","href":"/docs/v23.2/show-statistics"},{"title":"SHOW SAVEPOINT STATUS","sidebarTitle":"SHOW SAVEPOINT STATUS","href":"/docs/v23.2/show-savepoint-status"},{"title":"SHOW TABLES","sidebarTitle":"SHOW TABLES","href":"/docs/v23.2/show-tables"},{"title":"SHOW TRACE FOR SESSION","sidebarTitle":"SHOW TRACE FOR SESSION","href":"/docs/v23.2/show-trace"},{"title":"SHOW TRANSACTIONS","sidebarTitle":"SHOW TRANSACTIONS","href":"/docs/v23.2/show-transactions"},{"title":"SHOW TYPES","sidebarTitle":"SHOW TYPES","href":"/docs/v23.2/show-types"},{"title":"SHOW USERS","sidebarTitle":"SHOW USERS","href":"/docs/v23.2/show-users"},{"title":"SHOW VIRTUAL CLUSTER","sidebarTitle":"SHOW VIRTUAL CLUSTER","href":"/docs/v23.2/show-virtual-cluster"},{"title":"SHOW ZONE CONFIGURATIONS","sidebarTitle":"SHOW ZONE CONFIGURATIONS","href":"/docs/v23.2/show-zone-configurations"},{"title":"TRUNCATE","sidebarTitle":"TRUNCATE","href":"/docs/v23.2/truncate"},{"title":"UPDATE","sidebarTitle":"UPDATE","href":"/docs/v23.2/update"},{"title":"UPSERT","sidebarTitle":"UPSERT","href":"/docs/v23.2/upsert"},{"title":"WITH (storage parameter)","sidebarTitle":"WITH {storage parameter}","href":"/docs/v23.2/with-storage-parameter"}]},{"group":"Syntax","pages":[{"title":"Keywords \u0026 Identifiers","href":"/docs/v23.2/keywords-and-identifiers"},{"title":"Constants","href":"/docs/v23.2/sql-constants"},{"title":"Selection Queries","description":null,"href":"/docs/v23.2/selection-queries"},{"title":"Cursors","href":"/docs/v23.2/cursors"},{"title":"Table Expressions","description":null,"href":"/docs/v23.2/table-expressions"},{"title":"Common Table Expressions (WITH Queries)","sidebarTitle":"Common Table Expressions","href":"/docs/v23.2/common-table-expressions"},{"title":"Name Resolution","href":"/docs/v23.2/sql-name-resolution"},{"title":"NULL Handling","sidebarTitle":"NULL Handling","href":"/docs/v23.2/null-handling"},{"title":"Scalar Expressions","href":"/docs/v23.2/scalar-expressions"},{"title":"User-Defined Functions","href":"/docs/v23.2/user-defined-functions"},{"title":"Stored Procedures","href":"/docs/v23.2/stored-procedures"},{"title":"Window Functions","href":"/docs/v23.2/window-functions"},{"title":"SQL Grammar","sidebarTitle":"Full SQL Grammar","href":"/docs/v23.2/sql-grammar"}]},{"group":"Data Types","pages":[{"title":"Data Types","sidebarTitle":"Overview","href":"/docs/v23.2/data-types"},{"title":"ARRAY","sidebarTitle":"ARRAY","href":"/docs/v23.2/array"},{"title":"BIT","sidebarTitle":"BIT","href":"/docs/v23.2/bit"},{"title":"BOOL","sidebarTitle":"BOOL","href":"/docs/v23.2/bool"},{"title":"BYTES","sidebarTitle":"BYTES","href":"/docs/v23.2/bytes"},{"title":"COLLATE","sidebarTitle":"COLLATE","href":"/docs/v23.2/collate"},{"title":"DATE","sidebarTitle":"DATE","href":"/docs/v23.2/date"},{"title":"DECIMAL","sidebarTitle":"DECIMAL","href":"/docs/v23.2/decimal"},{"title":"ENUM","sidebarTitle":"ENUM","href":"/docs/v23.2/enum"},{"title":"FLOAT","sidebarTitle":"FLOAT","href":"/docs/v23.2/float"},{"title":"INET","sidebarTitle":"INET","href":"/docs/v23.2/inet"},{"title":"INT","sidebarTitle":"INT","href":"/docs/v23.2/int"},{"title":"INTERVAL","sidebarTitle":"INTERVAL","href":"/docs/v23.2/interval"},{"title":"JSONB","sidebarTitle":"JSONB","href":"/docs/v23.2/jsonb"},{"title":"OID","sidebarTitle":"OID","href":"/docs/v23.2/oid"},{"title":"SERIAL","sidebarTitle":"SERIAL","href":"/docs/v23.2/serial"},{"title":"STRING","sidebarTitle":"STRING","href":"/docs/v23.2/string"},{"title":"TIME / TIMETZ","sidebarTitle":"TIME","href":"/docs/v23.2/time"},{"title":"TIMESTAMP / TIMESTAMPTZ","sidebarTitle":"TIMESTAMP","href":"/docs/v23.2/timestamp"},{"title":"TSQUERY","sidebarTitle":"TSQUERY","href":"/docs/v23.2/tsquery"},{"title":"TSVECTOR","sidebarTitle":"TSVECTOR","href":"/docs/v23.2/tsvector"},{"title":"UUID","sidebarTitle":"UUID","href":"/docs/v23.2/uuid"}]},{"group":"Spatial Data","pages":[{"title":"Spatial Data Overview","sidebarTitle":"Overview","href":"/docs/v23.2/spatial-data-overview"},{"title":"POINT","sidebarTitle":"POINT","href":"/docs/v23.2/point"},{"title":"LINESTRING","sidebarTitle":"LINESTRING","href":"/docs/v23.2/linestring"},{"title":"POLYGON","sidebarTitle":"POLYGON","href":"/docs/v23.2/polygon"},{"title":"MULTIPOINT","sidebarTitle":"MULTIPOINT","href":"/docs/v23.2/multipoint"},{"title":"MULTILINESTRING","sidebarTitle":"MULTILINESTRING","href":"/docs/v23.2/multilinestring"},{"title":"MULTIPOLYGON","sidebarTitle":"MULTIPOLYGON","href":"/docs/v23.2/multipolygon"},{"title":"GEOMETRYCOLLECTION","sidebarTitle":"GEOMETRYCOLLECTION","href":"/docs/v23.2/geometrycollection"},{"title":"Well Known Text","sidebarTitle":"Well Known Text (WKT)","href":"/docs/v23.2/well-known-text"},{"title":"Well Known Binary","sidebarTitle":"Well Known Binary (WKB)","href":"/docs/v23.2/well-known-binary"},{"title":"GeoJSON","href":"/docs/v23.2/geojson"},{"title":"SRID 4326 - longitude and latitude","href":"/docs/v23.2/srid-4326"},{"title":"ST_Contains","sidebarTitle":"ST_Contains","href":"/docs/v23.2/st_contains"},{"title":"ST_Within","sidebarTitle":"ST_Within","href":"/docs/v23.2/st_within"},{"title":"ST_Intersects","sidebarTitle":"ST_Intersects","href":"/docs/v23.2/st_intersects"},{"title":"ST_CoveredBy","sidebarTitle":"ST_CoveredBy","href":"/docs/v23.2/st_coveredby"},{"title":"ST_Covers","sidebarTitle":"ST_Covers","href":"/docs/v23.2/st_covers"},{"title":"ST_Disjoint","sidebarTitle":"ST_Disjoint","href":"/docs/v23.2/st_disjoint"},{"title":"ST_Equals","sidebarTitle":"ST_Equals","href":"/docs/v23.2/st_equals"},{"title":"ST_Overlaps","sidebarTitle":"ST_Overlaps","href":"/docs/v23.2/st_overlaps"},{"title":"ST_Touches","sidebarTitle":"ST_Touches","href":"/docs/v23.2/st_touches"},{"title":"ST_ConvexHull","sidebarTitle":"ST_ConvexHull","href":"/docs/v23.2/st_convexhull"},{"title":"ST_Union","sidebarTitle":"ST_Union","href":"/docs/v23.2/st_union"}]},{"group":"Constraints","pages":[{"title":"Constraints","sidebarTitle":"Overview","href":"/docs/v23.2/constraints"},{"title":"CHECK Constraint","sidebarTitle":"Check","href":"/docs/v23.2/check"},{"title":"Default Value Constraint","sidebarTitle":"Default Value","href":"/docs/v23.2/default-value"},{"title":"Foreign Key Constraint","sidebarTitle":"Foreign Key","href":"/docs/v23.2/foreign-key"},{"title":"NOT NULL constraint","sidebarTitle":"Not Null","href":"/docs/v23.2/not-null"},{"title":"Primary Key Constraint","sidebarTitle":"Primary Key","href":"/docs/v23.2/primary-key"},{"title":"Unique Constraint","sidebarTitle":"Unique","href":"/docs/v23.2/unique"}]},{"title":"Functions and Operators","sidebarTitle":"Functions \u0026 Operators","href":"/docs/v23.2/functions-and-operators"},{"title":"Session Variables","href":"/docs/v23.2/session-variables"},{"title":"PL/pgSQL","href":"/docs/v23.2/plpgsql"}]},{"tab":"Reference","icon":"book","pages":[{"title":"Reference","href":"/docs/v23.2/architecture/glossary"}]},{"tab":"Cluster API","icon":"rocket","pages":[{"title":"Cluster API","href":"/docs/api/cluster"}]},{"tab":"Troubleshoot","icon":"bug","pages":[{"title":"Troubleshoot","href":"/docs/v23.2/troubleshooting-overview"}]}]},{"version":"v23.1","tag":"Unsupported","pages":[{"title":"v23.1","href":"/docs/v23.1/cursors"}]}]},{"product":"Cloud Deployments","icon":"cloud","description":"Fully managed CockroachDB","pages":[{"title":"Cloud Deployments","href":"/docs/cockroachcloud"}]},{"product":"Releases","icon":"list","description":"Version history, support policy \u0026 advisories","pages":[{"title":"Releases","href":"/docs/releases"}]}]},"basePath":"","title":"Cursors - CockroachDB","buildId":"dpl_8LJbrAiZvr1K98WQNZXCyY5AvT34","deploymentId":"dpl_8LJbrAiZvr1K98WQNZXCyY5AvT34","dynamics":["a74be98ba7"],"chunks":["zoom-image-lightbox-DMoL6lHz.js","lightbox-handle-r17bVUz3.js"]}