Skip to content

In SELECT ... INTO, the INTO should be on a separate line #864

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

Open
tordans opened this issue May 9, 2025 · 3 comments
Open

In SELECT ... INTO, the INTO should be on a separate line #864

tordans opened this issue May 9, 2025 · 3 comments

Comments

@tordans
Copy link

tordans commented May 9, 2025

Describe the Feature

Right now, the INTO is placed at the end of the last SELECT line.
This makes it quite hard to see.
When parsing the commands, I see SELECT but nothing that signals that this will create or modify a table. In fact, when I remove the INTO name, the formatting does not change.

I suggest to place the INTO on a new line to give it more visibility.

Currently:

SELECT
  r.*,
  nrm.idx INTO parking_driveways
FROM
  _parking_roads r
  JOIN _parking_node_road_mapping nrm ON r.osm_id = nrm.way_id
  JOIN parking_intersections i ON nrm.node_id = i.node_id
WHERE
  i.service_degree > 0
  AND i.degree <> i.service_degree
  AND r.is_service;

Improved:

SELECT
  r.*,
  nrm.idx
INTO parking_driveways
FROM
  _parking_roads r
  JOIN _parking_node_road_mapping nrm ON r.osm_id = nrm.way_id
  JOIN parking_intersections i ON nrm.node_id = i.node_id
WHERE
  i.service_degree > 0
  AND i.degree <> i.service_degree
  AND r.is_service;

Why do you want this feature?

I consider the INTO even more important than the SELECT but is has a lot less visibility ATM.


Interesting enough the Github code highlighting does not recognize INTO either…

@tordans tordans added the feature label May 9, 2025
@nene
Copy link
Collaborator

nene commented May 9, 2025

This SELECT ... INTO syntax is specific to PostgreSQL and not part of standard SQL.

It is properly supported by prettier-plugin-sql-cst.

Possibly it can be fairly easily supported in SQL Formatter. Need to check where else that INTO keyword might appear (besides INSERT INTO).

@nene nene added the postgresql label May 9, 2025
@nene nene changed the title Feature Request: Put INTO into a new line In SELECT ... INTO, the INTO should be on a separate line May 9, 2025
@nene nene added bug and removed feature labels May 9, 2025
@tordans
Copy link
Author

tordans commented May 12, 2025

FYI: My current workaround is to add a comment right before to force a new line.

FYI: I tried prettier-plugin-sql-cst but that fails with other issues related to DO END blocks and PostGIS data types.

tordans added a commit to FixMyBerlin/tilda-geo that referenced this issue May 13, 2025
The current formatter cannot handle INTO. I tried a different formatter which has other issues.

Workaround: Add a comment to force a new line.

sql-formatter-org/sql-formatter#864 (comment)
@pcnate
Copy link

pcnate commented May 21, 2025

This SELECT ... INTO syntax is specific to PostgreSQL and not part of standard SQL.

We use this all the time in Microsoft SQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants