--- via https://duckdb.org/docs/stable/sql/dialect/friendly_sql.html#trailing-commas
select
  42 as x,
  array['a', 'b', 'c',] as y,
  'hello world' as z,
;

-- trailing comma in column list
select * from t as u(a,);

-- missing comma
select a, b c  d, e from t;
--          ^ ^ comma missing
--          \-- this is a label

-- distinct on missing a comma
SELECT DISTINCT ON (a b) a, b, c
    FROM t
    order by a, b desc; 

-- group bys with missing commas
select * from t group by rollup (1 2 3);
select * from t group by cube (1 2 3);
select * from u
  group by grouping sets((1 2) grouping sets((), grouping sets(())));

-- trailing comma in args
select f(1,);

-- missing args
select f(a,,,,,);

-- in can only be used with tuples / sub queries
select 1 in c;

-- type cast must use a string literal
select numeric 1234;

-- missing comma
select array[1 2,3];
-- extra comma
select array[1, ,3];
-- trailing comma
select array[1,2,3,];

-- group by all, order by all
select * from t group by all order by all;

-- cast with malformed type mod args
select cast(x as varchar(100 200));
select cast(x as varchar(100, , 200));
select cast(x as t(a, b,));

-- regression test: this would cause the parser to get stuck & panic, now it
-- warns about a missing semicolon
select select;

-- extra comma
select a, from t;

-- case missing then expr
select case when 1 then end;

-- case missing when expr
select case when then x end;

-- case missing else expr
select case when 1 then 2 else end;

-- select without semi and trailing create table
select
create table users ();


-- select do
select 
do 'begin null; end';

-- select grant
select 
grant select on t to u;

-- where with missing expr
select from t where and c > 10;
select from t where or c != 'b';

select having and c > 10;
select having or c != 'b';

select from t join u on and true;
select from t join u on or true;

-- join after the where
select * from t
where x > 1
join k on true;

-- having after order by instead of before
with t as (select 2 b)
select 1 a from t
group by a
order by a
having a > 10;

-- select end
select
end;

-- select analyze/analyse
select
analyze;

select
analyse;

-- select with

select
with t as (select 1)
select * from t;

-- semicolon not allowed
(select 1;);

-- compound select requires a select on the left
select (1 union select 2);
select ((1) union select 2);
select (((((1)))) union select 1);

-- compound w/ empty parens
select 1 union ();

-- compound missing select
select * from (foo union select 1);

-- compound operators must precede trailing clauses
select 1 limit 1 union select 2;
select 1 order by 1 intersect select 2;
select 1 offset 1 except select 2;
select 1 fetch first 1 row only union select 2;
select 1 for update union select 2;

-- WITH is only allowed at the start of a compound select
select 1 union with x as (select 2) select * from x;

-- ALL and DISTINCT are only allowed before the first function argument
select f(1, all 2);
select f(1, distinct 2);

-- only column def list list allowed, not alias
select * from rows from (f() t);
select * from rows from (f() as t(a int));

-- column def columns a type
select * from rows from (f() as (a));

-- trailing comma at EOF
select 1,
