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.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive