nene / prettier-plugin-sql-cst

Prettier SQL plugin that uses sql-parser-cst

Home Page:https://nene.github.io/prettier-sql-playground/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`sqlDataTypeCase` and `sqlFunctionCase` options?

karlhorky opened this issue · comments

Similar to the dataTypeCase and functionCase in sql-formatter:

It seems like this would be much simpler to implement here, because according to SQL Explorer the node types already exist:

Screenshot 2023-12-03 at 12 37 22

Screenshot 2023-12-03 at 12 39 57

Yeah. It's definitely much simpler to achieve in here.

Also worth considering are the capitalization rules in SQLFluff. It implements 5 categories:

  • identifiers
  • keywords
  • types
  • literals (like NULL)
  • functions

It might be good to align our implementation with that. Though on the other hand I'd like to avoid configuration options and keep this plugin opinionated... but capitalization is an area where I've already decided that it's better for it to be configurable. This still leaves the question of picking the best defaults.

  • keywords and literals should default to uppercase (these literals are really just a subset of keywords)
  • identifier and function names to lower case (again, function names are a type of identifiers, though some dialects treat them as keywords. There are also some strange things like CURRENT_DATE which are functions, but with a special parenthesis-less syntax).
  • types... I'm not so sure about. Most dialects have a limited built-in set of types, but e.g. Postgres allows defining custom ones and SQLite pretty much ignores all type information. Most SQL I've come across to has types in uppercase though, which might be a better cross-dialect default.

Sounds reasonable to me 👍

Data types defaulting to uppercase is probably a good default too - the PostgreSQL docs seem like an outlier when it comes to their usage of lowercase data types