@@ -142,6 +142,7 @@ config ideas:
142142- lower / upper case keywords (default lowercase)
143143- indent (default 2)
144144- quoted idents (default avoid)
145+ - aliases (include ` as ` or not)
145146
146147links:
147148
@@ -279,6 +280,19 @@ alter table t
279280 alter column c type int;
280281` ` `
281282
283+ ### Rule : casing
284+
285+ ` ` ` sql
286+ select x as Foo from t;
287+ -- ^^^ casing: ` Foo ` will get parsed as ` foo ` .
288+ ` ` `
289+
290+ Autofixes to
291+
292+ ` ` ` sql
293+ select x as "Foo" from t;
294+ ` ` `
295+
282296### Rule : pointless cascade / restrict
283297
284298> These key words do not have any effect , since there are no dependencies on \$name .
@@ -409,6 +423,12 @@ suggests / autofixes to:
409423select * from t join u using (id, name, ip, description, meta);
410424` ` `
411425
426+ also offer an autofix back to natural join :
427+
428+ ` ` ` sql
429+ select * from t natural join u;
430+ ` ` `
431+
412432### Rule : using unsupported lambdas
413433
414434This actually parsers in Postgres , but could work off a heuristic
@@ -535,6 +555,19 @@ SELECT customer_id, merchant_id, request_id, count(*) from t
535555group by 1, 2, 3;
536556` ` `
537557
558+ ### Rule : missing column in group by
559+
560+ ` ` ` sql
561+ select a, b from t
562+ -- ^ b must appear in group by, quick fix:
563+ group by a;
564+
565+ -- becomes
566+
567+ select a, b from t
568+ group by a, b;
569+ ` ` `
570+
538571### Rule : unused column
539572
540573` ` ` sql
@@ -1005,7 +1038,7 @@ select * from (select case
10051038` ` `
10061039
10071040` ` `
1008- ( " case" : boolean )
1041+ case boolean
10091042` ` `
10101043
10111044unnest
@@ -1016,7 +1049,8 @@ select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']);
10161049` ` `
10171050
10181051` ` `
1019- (" unnest" : integer , " unnest" : text )
1052+ unnest integer ,
1053+ unnest text
10201054` ` `
10211055
10221056### Semantic Syntax Highlighting
@@ -1070,12 +1104,73 @@ becomes after filling in alias name with `b`
10701104select b .name , b .email from bar
10711105` ` `
10721106
1107+ ` ` ` sql
1108+ select * from (
1109+ select a , b from t where x > 10
1110+ );
1111+ -- ^ introduce alias
1112+
1113+ -- becomes
1114+
1115+ select * from (
1116+ select a , b from t where x > 10
1117+ ) as foo ;
1118+ ` ` `
1119+
10731120should prompt for table name for each entry when there is an ambiguous column
10741121
10751122related:
10761123
10771124- https://blog.jetbrains.com/datagrip/2019/03/11/top-9-sql-features-of-datagrip-you-have-to-know/#introduce_alias
10781125
1126+ ### Quick Fix: introduce table alias
1127+
1128+ ` ` ` sql
1129+ select t .a from t ;
1130+ -- becomes (with user input for value )
1131+ select t2 .a from t t2 ;
1132+ ` ` `
1133+
1134+ ### Quick Fix: flip \$ op
1135+
1136+ ` ` ` sql
1137+ select 1 > 2 ;
1138+ -- ^ flip >
1139+ select 1 < 2 ;
1140+
1141+ select 1 = 2 ;
1142+ -- ^ flip =
1143+ select 2 = 1 ;
1144+
1145+ -- etc , etc .
1146+ ` ` `
1147+
1148+ ### Quick Fix: flip join (may change semantics)
1149+
1150+ ` ` ` sql
1151+ select * from t join u using (u_id );
1152+ -- becomes
1153+ select * from u join t using (u_id );
1154+ ` ` `
1155+
1156+ ### Quick Fix: replace equality checks with ` in ` expression
1157+
1158+ ` ` ` sql
1159+ select * from t where a = 1 or a = 2 ;
1160+ -- becomes
1161+ select * from t where a in (1 , 2 );
1162+ ` ` `
1163+
1164+ ### Quick Fix: replace ` using ` with ` on `
1165+
1166+ ` ` ` sql
1167+ select * from t join u using (g_id );
1168+ ` ` `
1169+
1170+ ` ` ` sql
1171+ select * from t join u on t .g_id = u .g_id ;
1172+ ` ` `
1173+
10791174### Quick Fix: table to select
10801175
10811176` ` ` sql
@@ -1134,6 +1229,18 @@ related:
11341229
11351230- [datagrips expand wildcard](https://blog.jetbrains.com/datagrip/2019/03/11/top-9-sql-features-of-datagrip-you-have-to-know/#expand_wildcard)
11361231
1232+ ### Quick Fix: create table definition
1233+
1234+ ` ` ` sql
1235+ select a , b from t ;
1236+ -- ^ unknown table , quick fix : create table
1237+ -- becomes
1238+ create table t (a int not null , b int not null );
1239+ select a , b from t ;
1240+ ` ` `
1241+
1242+ We should have markers so you can quickly tab through and fill in the type and nullability for each field.
1243+
11371244### Quick Fix: field rename
11381245
11391246` ` ` sql
@@ -1249,4 +1356,111 @@ select 1 in (1,2,3);
12491356
12501357### Quick Fix: subquery to CTE
12511358
1252- ### Quick Fix: CTE to subquery
1359+ ` ` ` sql
1360+ select * from (select 1 );
1361+ -- becomes (with user input for value )
1362+ with t as (select 1 )
1363+ select * from t ;
1364+ ` ` `
1365+
1366+ ### Quick Fix: inline CTE
1367+
1368+ ` ` ` sql
1369+ with t as (select 1 )
1370+ select * from t ;
1371+ -- becomes
1372+ select * from (select 1 ) as t ;
1373+
1374+ with t (a ) as (select 1 )
1375+ select * from t ;
1376+ -- becomes
1377+ select * from (select 1 ) as t (a );
1378+ ` ` `
1379+
1380+ ### Quick Fix: qualify identifier
1381+
1382+ ` ` ` sql
1383+ create table foo .t (a int );
1384+ select a from t ;
1385+ -- ^ ?
1386+ -- becomes
1387+ select t .a from t ;
1388+ ` ` `
1389+
1390+ ` ` ` sql
1391+ create table t (a int );
1392+ select a from t ;
1393+ -- ^ ?
1394+ -- becomes
1395+ select a from public .t ;
1396+ ` ` `
1397+
1398+ ### Quick Fix: convert to subquery
1399+
1400+ ` ` ` sql
1401+ select a , b from t where x > 10 ;
1402+ -- ^ quickfix : convert to subquery
1403+
1404+ -- becomes
1405+
1406+ select * from (
1407+ select a , b from t where x > 10
1408+ );
1409+ ` ` `
1410+
1411+ ### Inlay Hints
1412+
1413+ [datagrip has good support](https://www.jetbrains.com/help/datagrip/inlay-hints.html) for these.
1414+
1415+ Column Names
1416+
1417+ ` ` ` sql
1418+ insert into t values (/* column_a: */ 1 , /* column_c: */ ' foo' );
1419+ ` ` `
1420+
1421+ ` ` ` sql
1422+ create view v (a , b ) as select /* a: */ 1 , /* b: */ ' foo' ;
1423+ ` ` `
1424+
1425+ ` ` ` sql
1426+ create view v (a , b ) as select /* a,y: */ * from foo ;
1427+ ` ` `
1428+
1429+ ` ` ` sql
1430+ with t (x , y ) as (
1431+ select /* x: */ 1 , /* y: */ 2
1432+ )
1433+ select x , y from t ;
1434+ ` ` `
1435+
1436+ ` ` ` sql
1437+ create table t (id int , a text , b int );
1438+ create table u (id int , a text , b int );
1439+
1440+ select * from t
1441+ union
1442+ select /* id: */ 1 , /* a: */ ' x' , /* b: */ ' y' from u ;
1443+ ` ` `
1444+
1445+ Function param names
1446+
1447+ ` ` ` sql
1448+ create function foo(x int ) returns text
1449+ as $$select 'foo'$$ language sql;
1450+
1451+ select foo (/* x: */ ' foo' );
1452+ ` ` `
1453+
1454+ Join cardinality
1455+
1456+ See datagrip docs
1457+
1458+ ` ` ` sql
1459+ select * from t join u /* 1<->1..n: */ using (user_id );
1460+
1461+ select * from t left join u /* 1<->0..n: */ using (user_id );
1462+
1463+ select * from t inner join u /* 1<->0..n: */ using (user_id );
1464+
1465+ select * from t full join u /* 0..n<->1: */ using (user_id );
1466+ ` ` `
0 commit comments