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

Wrong indentation in CREATE VIEW with optional clauses #60

Closed matteo-l closed 6 years ago

matteo-l commented 6 years ago

Create view statements are not correctly indented when some optional clause is used as shown in the following example. The optional clauses are defined in the MySQL manual.

-- without optional clauses
CREATE
  VIEW MyView AS
  SELECT DISTINCT table1.fieldA AS FirstField,
                  table2.fieldB AS SecondField
    FROM table1
       JOIN table2 ON table1.table1ID = table2.FKtable1;

-- with optional clauses
CREATE ALGORITHM = UNDEFINED DEFINER = user@localhost SQL SECURITY DEFINER
  VIEW MyView AS
  SELECT DISTINCT table1.fieldA AS FirstField,
  table2.fieldB AS SecondField
  FROM table1
  JOIN table2 ON table1.table1ID = table2.FKtable1;
alex-hhh commented 6 years ago

Thanks for reporting this problem. I have pushed a fix for this. Let me know if this fixes it for you.

matteo-l commented 6 years ago

The last version works correctly for me. Thank you

wmay commented 5 years ago

I have a similar issue, except with postgres and materialized.

-- without optional clauses
CREATE VIEW calibration_values AS
  select cal_day,
     cal_times,
     chemical,
     type,
     estimate_min_val(val, times, cal_day, site) as value
    from clock_audits
   where instrument='EPC';

-- with optional clauses
CREATE materialized VIEW calibration_values AS
  select cal_day,
  cal_times,
  chemical,
  type,
  estimate_min_val(val, times, cal_day, site) as value
  from clock_audits
  where instrument='EPC';