sql-formatter icon indicating copy to clipboard operation
sql-formatter copied to clipboard

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

Open tordans opened this issue 8 months ago • 3 comments

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 avatar May 09 '25 13:05 tordans

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 avatar May 09 '25 14:05 nene

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 avatar May 12 '25 15:05 tordans

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

We use this all the time in Microsoft SQL

pcnate avatar May 21 '25 22:05 pcnate