-
Notifications
You must be signed in to change notification settings - Fork 398
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
Place create table and table name in the same line #495
Comments
Hi. This is something that I've been wanting to change for a long time, but unfortunately the implementation of this touches on the core of how the SQL gets parsed inside formatter, so it's not that simple to change. I've been slowly moving towards this goal, but hard to tell when we get there. |
ok |
Copying over the simpler example from @kiwicopple in #570 for additional illustration of the problem: Input data Which SQL and options did you provide as input? create table profiles (
id bigint primary key,
name text not null,
dob date
); Expected Output create table profiles (
id bigint primary key,
name text not null,
dob date
); Actual Output create table
profiles (
id bigint primary key,
name text not null,
dob date
); |
@nene could you expand with a few paragraphs about the details here? (which files/methods are interesting, where are the challenges and potentially problematic areas) Maybe a community member would be open to diving in and implementing this. |
Come to think of this again. I think there's actually a rather trivial fix for this. Just need to move |
Opened a PR (#688) to implement this fix 🙂 |
Is there a way for this to be applied to WITH clauses as well? @nene Maybe exposed via a setting? The output currently is like: WITH
UniqueShipments AS (
SELECT DISTINCT
amsh.[shipment_id],
amsh.[sub_id],
amsh.[shipment_date]
FROM
amazon_shipment amsh
) WITH UniqueShipments AS (
SELECT DISTINCT
amsh.[shipment_id],
amsh.[sub_id],
amsh.[shipment_date]
FROM
amazon_shipment amsh
) |
The problem with WITH clause is that it can have multiple items, like: WITH
foo AS (SELECT ...),
bar AS (SELECT ...) If same change were to be implemented in WITH-clause as was done with CREATE TABLE, the above would get formatted as: WITH foo AS (SELECT ...),
bar AS (SELECT ...) Ideally the formatter would understand how many items a WITH clause has and adjust the formatting accordingly, but unfortunately SQL Formatter doesn't quite understand much about the context. It pretty much looks at the code one keyword at a time and tries to make the best formatting decisions. |
That makes sense, but since I tend to write quite long CTE's, I honestly never minded the issue shown in the second example. But, it does make sense as to why that shouldn't be done, it would be an eye sore for shorter CTE's. |
Describe the Feature
hi bro.
for hive sql, can we put create table and table name in the same line? currently there is a new line after CREATE TABLE IF NOT EXISTS , so the table name will be in another line
Why do you want this feature?
to make the sql code more compact
currently there will be 2 layers of indent
The text was updated successfully, but these errors were encountered: