alex-hhh / emacs-sql-indent

Syntax based indentation for SQL files inside GNU Emacs
GNU General Public License v3.0
121 stars 18 forks source link

PostgreSQL CREATE EXTENSION IF NOT EXISTS #97

Closed RomanHargrave closed 4 years ago

RomanHargrave commented 4 years ago

sql-indent-mode appears to be confused by the IF NOT clause that may appear in pgSQL's CREATE EXTENSION statement. See the following example -


CREATE EXTENSION "uuid-ossp" WITH SCHEMA public;

-- indentation is correct here

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public
                   -- invalid syntax, but this treated as a block
END;

-- indentation is correct here

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
                   -- autoindents to this level

sql-product is set to postgres.

alex-hhh commented 4 years ago

Thanks for reporting this. I pushed a fix for this, you can check it out.

Note however that the invalid syntax line is not detected where you point it out, but it will be detected at the "END" statement and the next "CREATE" statement. The aim of sql-indent is not really to detect syntax errors in SQL code, and this error detection is very limited -- I have no plans to improve that, as it would be a lot of work.

RomanHargrave commented 4 years ago

Thanks! I'll take a look

Note however that the invalid syntax line is not detected where you point it out

Ah, sorry for the confusion there. I used this as an example to try and illustrate how I thought this was happening. The invalid syntax bit was just an acknowledgement that the CREATE ... END; statement given wasn't something that would occur in the wild.