sqlfmt icon indicating copy to clipboard operation
sqlfmt copied to clipboard

Format the code of the UDF found within `create function` statements

Open tconbeer opened this issue 3 years ago • 3 comments

for the udfs defined in create function statements, the code for the function itself is usually passed in as a string. Today we don't apply any formatting to this string (we treat it like any other quoted name, as data). But for language sql and language python udfs, it should be possible to format these functions, either natively or using black.

It may be tricky/dangerous to try to unquote and re-quote these functions.

We also don't have any way to track state (and/or find the language and code tokens), and conditionally apply formatting if one of the two known languages are used.

So generally this is probably not a good idea and not in the near-term roadmap; mostly noting this in case something similar comes along when working on other ddl/dml statements.

tconbeer avatar Oct 31 '22 18:10 tconbeer

Related: consider formatting code in set blocks, if we can clearly detect that it's sql (e.g., if it starts with select ...). This is maybe a bad idea, but inspired from #326

tconbeer avatar Nov 28 '22 17:11 tconbeer

I guess would also need to detect with block? What would it take to implement this? Do you have any pointers?

brtkwr avatar Jul 24 '24 06:07 brtkwr

Mostly interested in formatting code inside set block or that inside multiline string block within '''select * from foo'''

brtkwr avatar Jul 24 '24 06:07 brtkwr