Skip to content
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

Proposal: Format SQL Query option in the Native Query Editor #9142

Closed
sowrabh opened this issue Dec 17, 2018 · 9 comments · Fixed by #38113
Closed

Proposal: Format SQL Query option in the Native Query Editor #9142

sowrabh opened this issue Dec 17, 2018 · 9 comments · Fixed by #38113
Assignees
Labels
Querying/Native The SQL/native query editor Type:New Feature
Milestone

Comments

@sowrabh
Copy link

sowrabh commented Dec 17, 2018

Proposal

One minor annoyance today in using the Native Query Editor in Metabase is the lack of an option to format/prettify queries.

So I propose to add a Format Query option to the Native Query Editor(See screenshot below for a mockup). If this is something that is of interest to the community, I can help contribute to the same.

screenshot 2018-12-17 at 4 43 19 pm

⬇️ Please click the 👍 reaction instead of leaving a +1 or update? comment

@jornh

This comment has been minimized.

@sowrabh

This comment has been minimized.

@gvisniuc

This comment has been minimized.

@tbillington

This comment has been minimized.

@ajubin
Copy link

ajubin commented Aug 4, 2022

Hey,

I'm writing a lot of sql queries for custom dashboard and reports, I'd love to see a "format SQL" button to clean my mess 🧹

I've started to look at the possibilities, from my understanding we should modify this file frontend/src/metabase/query_builder/components/NativeQueryEditor.jsx to add a library like this one https://github.com/sql-formatter-org/sql-formatter

The main issue here, is to support the placeholders like {{some_input}}, {{#ref_to_another_table}}, [[AND optionnal_condition]] but the library proposed can't handle those special tokens.

I think one should dig into SQL parsers to properly format and lint the specifities of the metabase's SQL.

The facebook SQL editor daiquery seems to handle this, see here in SQL Editing section

Still, you can try the other formatting options here https://sql-formatter-org.github.io/sql-formatter/

Does anyone has more info on this ?

@samuelT2

This comment was marked as spam.

@lucasgadams
Copy link

Any update on this? Would be really nice!

@lucasgadams
Copy link

@ajubin as a former meta employee, i can say that Daiquery is honestly amazing and supported a lot of very nice things. Automatic formatting and automatic linting looking for errors are two of the main things I feel matabase is lacking. Been looking for a replacement for Daiquery since i left...

@alxnddr alxnddr mentioned this issue Jan 25, 2024
1 task
@alxnddr alxnddr self-assigned this Jan 26, 2024
@alxnddr alxnddr added this to the 0.49 milestone Jan 31, 2024
@ohld
Copy link

ohld commented Apr 26, 2024

Is it possible to force SQL formatting for all SQL questions? I don't like when my users create unreadable SQL queries and don't CAPITALIZE reserved words like SELECT, FROM and WHERE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Querying/Native The SQL/native query editor Type:New Feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.