Error creating query using python and pydomo
Hello,
When attempting to query a dataset with a simple query
query = {"sql": "SELECT * FROM table"}
I get this exception
Exception: Error creating query: {"status":400,"statusReason":"Bad Request","message":"Cannot deserialize instance of `java.lang.String` out of START_OBJECT token"
Using domo.ds_meta and domo.ds_get work fine, but I need to be able to query a larger dataset.
Thank for any help you can offer!
Best Answers
-
Hi @taylordomo
Do you have any extra code / context for how you're calling ds_query?
Are you passing your dictionary as the query or just the query string? Looking at the code for the query function it looks like it does the packaging automatically for you so you shouldn't need to pass in {"sql": "select * from table"} but rather just pass in your query itself "select * from table"
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
Yes! Changing the query to a string worked. Now that I look around, I am not sure where I got the idea that I needed a dictionary. For others that have this same issue:
query = "SELECT * FROM table"
df = domo.ds_query(dataset_id=dataset_id, query=query, return_data=True)
Is the correct code to get the querying to work. Query needs to be a string, not a dictionary.
Appreciate the help!
0 -
Hi, I wanted to follow up on this thread in case someone else has an issue running ds_query. For me, as of December 2022, if the query string has incorrect sql syntax, I receive this exception error:
Exception: Error creating query: There was a problem executing the SQL query: Underlying service error: Internal Server Error
I am not sure why it says it's an internal error because it's just a sql syntax error. Some tips for getting your syntax correct.
- The simplest query you can run is to select all. If you have a dataset with less than 1 million rows, I would recommend this first to make sure your client id, secret id, and dataset id all check out.
- that said, I'm betting the main use case for using ds_query is to actually select specific columns and filter using where. To select particular columns, if the column does not have any spaces in the name, you can type it how it's spelt.
- if the column name has spaces, I've found that using back quotes works for me
- then if you want to filter, obviously use the WHERE clause
- one thing to be diligent on, is to make sure you have space between table and WHERE so I add a space or two after table (blue arrow)
Hopefully this helps someone get started with this function!
0
Answers
-
what happens when you don't use SELECT * and actually select column names?
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
Hey, I appreciate the idea! I'm getting the same exception with any of these:
{"sql": "SELECT name, id FROM table"}
{"sql": "SELECT name, id FROM table Limit 3"}
0 -
Hi @taylordomo
Do you have any extra code / context for how you're calling ds_query?
Are you passing your dictionary as the query or just the query string? Looking at the code for the query function it looks like it does the packaging automatically for you so you shouldn't need to pass in {"sql": "select * from table"} but rather just pass in your query itself "select * from table"
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
Yes! Changing the query to a string worked. Now that I look around, I am not sure where I got the idea that I needed a dictionary. For others that have this same issue:
query = "SELECT * FROM table"
df = domo.ds_query(dataset_id=dataset_id, query=query, return_data=True)
Is the correct code to get the querying to work. Query needs to be a string, not a dictionary.
Appreciate the help!
0 -
Hi, I wanted to follow up on this thread in case someone else has an issue running ds_query. For me, as of December 2022, if the query string has incorrect sql syntax, I receive this exception error:
Exception: Error creating query: There was a problem executing the SQL query: Underlying service error: Internal Server Error
I am not sure why it says it's an internal error because it's just a sql syntax error. Some tips for getting your syntax correct.
- The simplest query you can run is to select all. If you have a dataset with less than 1 million rows, I would recommend this first to make sure your client id, secret id, and dataset id all check out.
- that said, I'm betting the main use case for using ds_query is to actually select specific columns and filter using where. To select particular columns, if the column does not have any spaces in the name, you can type it how it's spelt.
- if the column name has spaces, I've found that using back quotes works for me
- then if you want to filter, obviously use the WHERE clause
- one thing to be diligent on, is to make sure you have space between table and WHERE so I add a space or two after table (blue arrow)
Hopefully this helps someone get started with this function!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive