-
Notifications
You must be signed in to change notification settings - Fork 3.9k
sql: support SQL declare (cursor) #41412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Zendesk ticket #3853 has been linked to this issue. |
I can easily fix this by adding Cockroach as a supported database driver to Tableau. Only thing you have to do is to set If you're interested I can show how to do build a proper driver customization for Tableau... |
OK, I tested it and works like a charm. Code is here: https://github.com/tfoldi/tableau_cockroachdb_connector |
cc @jordanlewis |
this is needed for QGIS support for PostGIS. |
@otan, could you say more? Including links to sample queries or use cases would be very helpful. |
QGIS uses and then FETCH: https://github.com/qgis/QGIS/blob/b4c21fa44e25c23c9ee542f56f031b3de1a94fea/src/providers/postgres/qgspostgresconn.cpp#L1698 ... all for the sake of deducing endianness :3 this is a startup sequence; i'm unable to open the tool without it, unfortunately. QGIS is a widely used (and quite neat!) open source geospatial plotting tool as well. |
Maybe, but I found something perhaps even more useful -- the Modifying this code is hard because it works on a general cause, and it has no way to paginate results otherwise. |
Note that there is more support required than just
@otan would it be possible for you to run some of these tools against Postgres and collect a log of the statements produced? I would like to make sure we are not missing any other features. Significantly, if you can figure out whether "multiple active result sets" are used (aka - are there other SQL statements intereleaved in between the cursor FETCH statements on the same connection?) that would be very helpful for effort estimation. |
I would also be curious to see the comprehensive list of tools we need to support for spatial, and of that list, which tools require cursor support. I continue to find it surprising that geospatial tools all need DECLARE CURSOR. Why would that be exactly? Is this a case of 2 tools (ogr2ogr and qgis) needing the feature making it seem like they all do? Do they actually all need cursors? And in the latter case, why is that exactly? Is it because they're old? Sorry for all of the questions. I feel we need an improved understanding of the situation here to appropriately understand and prioritize this work. |
See logs: https://drive.google.com/drive/folders/1IQ8Y3VvsrcbEAaQku3d3vXJuPVcWHu5W?usp=sharing
AFAICT from reading code (they're both open source), they do not require anything like these -- just lots of FETCHes to get lots of data. |
I'm not sure exactly why -- my guess is that it's easy to say "fetch me all data in a paginated manner" without having to read the schema and figure out exactly how it works. |
I will also note ArcGIS also required DECLARE CURSOR -- I've included it in the folder. |
I don't think we've got a comprehensive list anywhere (@awoods187 do you?) -- these are ones that came up that seem popular in either import/export of data (ogr2ogr is the tool) or visualisations (ArcGIS is an extremely well known and used proprietary tool, QGIS is referenced and used heavily from visualisations I've seen on other websites). |
How do I install it to my tableau? Just starting using tableau. I want to connect my cockraochDB to tableau and visualize the data on it. |
The process is documented here: https://tableau.github.io/connector-plugin-sdk/docs/share |
Do you have plans to implement cursor support? |
not yet @xvaara -- do you have a use case to share with us? this helps with prioritisation! |
Hi @otan, I hope this will help to prioritize this feature |
I have many triggers, functions etc. so I can't use crdb. But I'd like to use it via postgres_fdw to sync instances and save versioning data. But I'd need to access that directly from postgresql. I'm thinking I'll try to use dblink if this still isn't on the roadmap. I asked about it somewhere few years ago. |
I also ran into this while experimenting with accessing cockroachdb via the postgres_fdw extension. I was curious to see if it's possible to use FDW as part of the solution to incrementally migrating from postgres to cockroachdb. Possibly by creating a view that sits on top of the same table in postgres and cockroach, making them look like a single table to users of the database. I followed the postgres_fdw setup docs and importing the cockroachdb table into postgres appeared to work, however querying it fails. Here's how it looks from the postgres side: experiment=# \dE
List of relations
Schema | Name | Type | Owner
--------+-------+---------------+----------
public | users | foreign table | postgres
experiment=# \d+ users
Foreign table "public.users"
Column | Type | Collation | Nullable | Default | FDW options | Storage | Stats target | Description
--------+-------------------+-----------+----------+---------+-----------------------+----------+--------------+-------------
id | bigint | | not null | | (column_name 'id') | plain | |
uuid | uuid | | | | (column_name 'uuid') | plain | |
email | character varying | | | | (column_name 'email') | extended | |
name | character varying | | | | (column_name 'name') | extended | |
Server: cockroachdb
FDW options: (schema_name 'public', table_name 'users')
experiment=# select * from users limit 1;
ERROR: at or near "declare": syntax error: unimplemented: this syntax
DETAIL: source SQL:
DECLARE c1 CURSOR FOR
^
HINT: You have attempted to use a feature that is not yet implemented.
See: https://go.crdb.dev/issue-v/41412/v20.2
CONTEXT: remote SQL command: SELECT id, uuid, email, name FROM public.users LIMIT 1::bigint |
74006: sql: add support for DECLARE, FETCH, CLOSE CURSOR using internal executors r=jordanlewis a=jordanlewis Touches #41412. This PR implements the SQL CURSOR methods DECLARE, FETCH and CLOSE using streaming internal executors. Here's the Postgres docs on DECLARE: https://www.postgresql.org/docs/current/sql-declare.html Things it implements: - DECLARE for forward-only cursors - FETCH forward, relative, and absolute variants for forward-only cursors - CLOSE a cursor - pg_catalog.pg_cursors Things it's missing: - BINARY CURSOR support, which returns data in the Postgres binary format - MOVE support, which allows advancing the cursor without returning any rows. This should be quite similar to FETCH. - WITH HOLD support (allows keeping a cursor open for longer than a transaction by writing its results into a buffer) - Scrollable cursor (reverse fetch) support, we'd have to implement this also by savings results into a buffer. - FOR UPDATE support - Respect for `SAVEPOINT`. Cursor definitions will not disappear if rolled back to a savepoint before they were created. But we also don't do this right for settings (see #69396) so I don't think this is a major problem. Co-authored-by: Jordan Lewis <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Is your feature request related to a problem? Please describe.
A customer tried to use tableau to connect to cockroachDB, using this guide.
Tableau uses
declare
for its queries, CockroachDB does not currently support compatibility with SQL level declare.Tableau can not be used.
Describe the solution you'd like
Support for the declare keyword.
postgres docs on declare.
Epic: CRDB-11397
The text was updated successfully, but these errors were encountered: