CREATE OR REPLACE FUNCTION public.setof_test()
RETURNS SETOF text
LANGUAGE sql
STABLE STRICT
AS $function$
select unnest(array['hi', 'test'])
$function$
;Sqlfluff the SQL Linter for Humans
21–30 of 95 posts
Re: Sqlfluff the SQL Linter for Humans
#22There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc
select a
, b
, count(*) as count
from table
join table2 on table.key1 = table2.key1
and table.key2 = table2.key2
and DATEADD('day', 1, table.key3) = table2.key3
where cond1
and cond2
group by a, b
order by count desc
For me this lets me read the SQL query almost like a picture at first glance, identifying blocks of rivers as semantically connected groups of statements. Some SQL formatters out there love to put join clauses at the same indentation level as the join itself, drives me nuts.Re: Sqlfluff the SQL Linter for Humans
#23There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc
Re: Sqlfluff the SQL Linter for Humans
#24There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc
I hate you and and the awful layout you have just introduced me to... Also, that is how I will be formatting all my SQL from now on.
SELECT
a, b, COUNT(*) as count
FROM
table
WHERE
cond1 AND cond2
GROUP BY
a, b
ORDER BY
count DESCRe: Sqlfluff the SQL Linter for Humans
#25There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc
Leading comma is configurable, but I wouldn't know if the linter allows for that layout. Can't say I've seen it before, is it specific to a particular development environment?
Re: Sqlfluff the SQL Linter for Humans
#26There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc
from ...
where ...
group ...
having ...
select ...
order by ...
limit ...Re: Sqlfluff the SQL Linter for Humans
#27This is a linter which complains about spaces and newlines, but lets "WHERE col = NULL" pass (which can never be meaningful) just fine? Obviously this depends on the rules configuration, but just judging that first smell test, it seems very ill thought out.
Re: Sqlfluff the SQL Linter for Humans
#28Earlier quoted context omitted.
Leading comma is configurable, but I wouldn't know if the linter allows for that layout. Can't say I've seen it before, is it specific to a particular development environment?
I've seen it a lot in Data Science/Analytics environments, as it allows for faster query iterations than trailing commas.
I personally disobey both recommendations (I mean, the book is worth it for other reasons) but both those conventions are very commonly used.
I meant more the the "center" layout that the commenter above was describing, it'd seem quite laborious to maintain by hand in most environments, if not using a particular one that supports it out of the box.
Re: Sqlfluff the SQL Linter for Humans
#29There surely is a need for a sql linter, but if it wants to be strict about syntax style, it should better familiarize itself with not-noob styles first. Eg. some people like to align the clauses vertically and use a leading, not trailing, comma. select a , b , count(*) as count from table where cond1 and cond2 group by a, b order by count desc
Or the ultimate pedant (pedultimate?) order which matches the SQL order of operations (which for some queries can be illuminating): from ... where ... group ... having ... select ... order by ... limit ...
Edit: misread and select was in the middle in that comment
Re: Sqlfluff the SQL Linter for Humans
#30I wondered how much good you could do with an SQL linter that didn't have any access to the underlying schema, and the answer seems to be "mostly whitespace and capitalization issues".
Makes you wonder if this tool would be better a code formatter rather than linter?
The authors should probably be selling it on that point since it seems to be its strength, it doesn't have many rules along the lines of the static analysis that people look for in linters.
Some people (tech leads, CTOs) care a lot about formatting but I wouldn't make teammates go through a linter for that, it's a rather surface concern.