django-sql-explorer | Easily share data across your company via SQL queries | SQL Database library
kandi X-RAY | django-sql-explorer Summary
kandi X-RAY | django-sql-explorer Summary
Easily share data across your company via SQL queries. From Grove Collab.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Handles the POST request
- Generate tokens from a list
- Render an explorer page
- Returns a boolean indicating if the sql matches the whitelist
- Render a query
- Extract parameters from text
- Generate context variables
- Return a list of available query parameters
- Snapshot a query
- Get output
- Uploads data to S3
- Get the xlsx output
- Format the title
- Adds context data to context
- Overrides dispatch
- Called once
- Returns a queryset of QueryLog
- Build context data
- Check if the user has permission to view
- Returns a queryset of QueryLogs
- Create a query
- Return a list of Snapshot objects
- Get the version string
- Handle GET request
- View of a schema
- Format a SQL statement
django-sql-explorer Key Features
django-sql-explorer Examples and Code Snippets
Community Discussions
Trending Discussions on django-sql-explorer
QUESTION
Our Django application just migrated from MySQL to PostgreSQL, and we are in the process of updating our user queries to use the correct syntax. These queries are stored/executed via Django-SQL-Explorer.
I have a query that for simplicity's sake looks like this:
SELECT * FROM table t WHERE t.scheduled_start_date BETWEEN $$from_date$$ AND $$to_date$$
The query above works, but I would like to set defaults for today & today+30 respectively.
I've tried the following WHERE clauses to no avail:
Works with user entered date, default throws syntax errorWHERE t.scheduled_start_date BETWEEN date('$$from_date:CURRENT_DATE$$') AND date('$$to_date:CURRENT_DATE + INTERVAL \'30 DAY\'$$')
Error using defaults:
syntax error at or near "30" LINE 28: ...urrent_date') AND date('current_date + interval \'30 day\'') ^
WHERE t.scheduled_start_date BETWEEN date($$from_date:CURRENT_DATE$$) AND date($$to_date:CURRENT_DATE + INTERVAL '30 DAY'$$)
Error with user dates:
function date(integer) does not exist LINE 28: WHERE t.scheduled_start_date BETWEEN date(2019-09-30) AND da... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.
The message about casting makes sense to me since the user enters in string data, however I can't seem to get the syntax right that casts to DATE but only when the default is overridden.
Any suggestions would be helpful. Thanks!
...ANSWER
Answered 2019-Nov-08 at 23:10Your input is a string value, current_date
is a function call. The former needs quotes whereas the latter does not. Therefore your client side substitution will not work. You can move the default logic into the SQL statement using the COALESCE()
function doc.
In case the client sends NULL values for an empty user input this would result in the following where clause:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-sql-explorer
You can use django-sql-explorer like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page