§

SQL queries format ചെയ്യുക

ഡയലക്ട്
ഇൻഡന്റ്
കീവേഡ് കേസ്
Clause-ന് മുൻപ് linebreak
§

SQL paste ചെയ്യൂ

§

ഫോർമാറ്റ് ചെയ്ത SQL

കേരളത്തിലെ data engineering ടീമുകൾ dbt projects, PostgreSQL/BigQuery warehouses, AWS Athena queries-ൽ consistent SQL formatting enforce ചെയ്യുന്നു. ഒരു engineer 200-line CTE hand-format ചെയ്ത്, മറ്റൊരാൾ single line ആക്കി paste ചെയ്‌താൽ PR diff noise ആകുന്നു — actual logic change hide ആകുന്നു. Commit-ന് മുൻപ് formatter run ചെയ്‌താൽ review cycles കുറയുന്നു, column-order diff reviewer-ന് clearly കാണാൻ കഴിയുന്നു.

SQL formatting എങ്ങനെ പ്രവർത്തിക്കുന്നു

SQL formatting ഒരു lexer-driven rewrite ആണ് — query-ൽ ഓരോ token-ഉം walk ചെയ്ത്, chosen dialect-ന്റെ rules പ്രകാരം ചുറ്റും whitespace re-emit ചെയ്യുന്നു. Query semantics ഒരിക്കലും മാറുന്നില്ല, layout മാത്രം.

  1. Dialect തിരഞ്ഞെടുക്കൂ. MySQL backticks, PostgreSQL :: casts, BigQuery dotted table paths, T-SQL square-bracket identifiers — ഓരോന്നിനും അറിയാവുന്ന tokenizer ആവശ്യമാണ്. Dialect selector ഏത് grammar apply ചെയ്യണം എന്ന് തിരഞ്ഞെടുക്കുന്നു.
  2. Input tokenize ചെയ്യൂ. Formatter query-ഒരു token stream ആക്കുന്നു: keywords (SELECT, JOIN), identifiers, literals, operators, parentheses, comments. String literals, quoted identifiers untouched pass through ചെയ്യുന്നു.
  3. Layout rules apply ചെയ്യൂ. Top-level clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY) സ്വന്തം line-ൽ start ചെയ്യുന്നു. Select list, column lists-ൽ comma-separated expressions ഓരോന്നും chosen indent unit-ൽ indented ആക്കി ഒരു line ലഭിക്കുന്നു.
  4. Keyword case apply ചെയ്യൂ. Keyword-case toggle recognised SQL keywords uppercase, lowercase ആക്കുന്നു, അല്ലെങ്കിൽ input casing verbatim preserve ചെയ്യുന്നു. Identifiers ഒരിക്കലും touch ചെയ്യുന്നില്ല — column, table names എഴുതിയ പോലെ.
  5. Formatted string emit ചെയ്യൂ. Token stream indent character (2 spaces, 4 spaces, tab), configured linebreak rule ഉപയോഗിച്ച് ഒരൊറ്റ string-ൽ join ചെയ്യുന്നു. Live mode type ചെയ്യുമ്പോൾ 200 ms debounce-ൽ whole pipeline re-run ചെയ്യുന്നു.

SQL pretty-print ചെയ്യേണ്ടത് എന്തുകൊണ്ട്

  • Pull-request diff വായനാക്ഷമത. 200-line CTE ഒരു line ആക്കി rewrite ചെയ്‌താൽ code review ഒരു guessing game ആകുന്നു. Consistent formatting diff-നെ actual change-ലേക്ക് scoped ആക്കുന്നു — ഒരു new column, extra JOIN, different WHERE predicate — reviewer whitespace untangle ചെയ്യാതെ കാണുന്നു.
  • Debugging എളുപ്പം. Query wrong row count return ചെയ്‌താൽ ആദ്യം line by line read ചെയ്യുന്നു. Formatted SQL ഓരോ JOIN-ഉം സ്വന്തം line-ൽ, WHERE predicates aligned — missing AND, stray OR ഒറ്റനോട്ടത്തിൽ കണ്ടെത്തുന്നു.
  • ടീമിൽ ഏകീകൃത ശൈലി. മിക്ക ടീമുകളും SQL style guide adopt ചെയ്യുന്നു (dbt Labs, GitLab, Mode Analytics publish ചെയ്യുന്നു). Commit-ന് മുൻപ് formatter run ചെയ്‌താൽ review-ൽ style argument ഒഴിവായി logic ചർച്ച മാത്രം.
  • Docs-ൽ SQL share ചെയ്യൽ. Runbooks, incident retros, Notion docs — top-to-bottom read ചെയ്യാൻ കഴിയുന്ന SQL benefit ചെയ്യുന്നു. Formatted SQL fenced code block-ൽ cleanly paste ആകുന്നു, PDF exports-ൽ predictably print ആകുന്നു.

പൊതു ആപ്ലിക്കേഷനുകൾ

SQL formatting analytics engineering, backend development, operations work-ൽ — query write ചെയ്യാത്ത ഒരാൾ read ചെയ്യേണ്ടിടത്ത് ഉണ്ടാകും.

  • Analytics engineering: dbt project-ൽ pre-commit hook ഓരോ model file-ഉം reformat ചെയ്ത് PR diffs logic changes-ലേക്ക് scoped ആക്കുന്നു.
  • Database administration: one-line slow-query log entry paste ചെയ്ത്, format ചെയ്ത്, incident retro എഴുതുമ്പോൾ join order walk ചെയ്യൂ.
  • Documentation: Looker explore, Tableau workbook-ൽ നിന്ന് query format ചെയ്ത് runbook-ൽ copy-pasteable example ആക്കൂ.

ഒരു ഉദാഹരണം

Dialect PostgreSQL, indent 2 spaces, keyword case UPPER ആക്കി SELECT u.id,u.email,COUNT(o.id) FROM users u LEFT JOIN orders o ON o.user_id=u.id WHERE u.created_at > '2024-01-01' GROUP BY u.id,u.email ORDER BY u.id; input pane-ൽ paste ചെയ്യൂ. Output-ൽ SELECT, FROM, LEFT JOIN, WHERE, GROUP BY, ORDER BY സ്വന്തം lines-ൽ; select list, group-by list-ലെ ഓരോ column-ഉം indented line-ൽ; ON predicate JOIN keyword-ഉ ഒരു indent deeper. BigQuery dialect-ൽ ഇതേ query ഒരേ output produce ചെയ്യും — backtick-quoted identifiers ഉണ്ടെങ്കിൽ preserve ചെയ്യുന്നു.

FAQ

ഏത് SQL dialects support ചെയ്യുന്നു?

Dialect dropdown Standard SQL, MySQL, PostgreSQL, SQLite, MariaDB, Transact-SQL (SQL Server / Azure SQL), BigQuery, Snowflake, Redshift cover ചെയ്യുന്നു. Underlying sql-formatter library DuckDB, Spark SQL, Hive, Trino, Db2, N1QL, PL/SQL, ClickHouse, TiDB, SingleStoreDB recognise ചെയ്യുന്നു — list-ൽ ഇല്ലാത്ത target-ന് closest dialect tuck sensible output produce ചെയ്യുന്നു. Identifiers, string literals, dialect-specific operators (PostgreSQL @>, BigQuery SAFE. prefixes) verbatim preserve ചെയ്യുന്നു.

ഇത് SQL validate ചെയ്യുമോ?

ഇല്ല. Formatter ഒരു lexical rewriter — parser ഇല്ല. Input tokenize ചെയ്ത്, layout rules apply ചെയ്ത്, result emit ചെയ്യുന്നു; query semantically valid ആണോ, referenced tables exist ചെയ്യുന്നുണ്ടോ, chosen dialect-ൽ syntax legal ആണോ — check ചെയ്യുന്നില്ല. Real correctness check-ന് actual database (അല്ലെങ്കിൽ SQLFluff) ഉപയോഗിക്കൂ.

Keywords uppercase ആകുന്നത് എന്തുകൊണ്ട്?

Keyword case dropdown default UPPER — published SQL style guides (dbt Labs, Mode, GitLab) convention. Team lowercase select/from ഉപയോഗിക്കുന്നെങ്കിൽ lower switch ചെയ്യൂ, typed casing keep ചെയ്യാൻ Preserve. Identifiers ഒരിക്കലും affect ആകുന്നില്ല — recognised keyword set മാത്രം rewrite ആകുന്നു.

Query എവിടെയെങ്കിലും upload ആകുന്നുണ്ടോ?

ഇല്ല. Vendored sql-formatter library ബ്രൗസറിൽ run ചെയ്യുന്നു, formatting locally നടക്കുന്നു, query text network cross ചെയ്യുന്നില്ല. ഈ page make ചെയ്യുന്ന outbound requests tools.ultim8soft.com-ൽ ഓരോ page-ഉം make ചെയ്യുന്ന shared analytics, ads requests; SQL text ഏതിന്റെയും ഭാഗമല്ല.

Formatter കൈകാര്യം ചെയ്‌താൽ Pretty-printed SQL ഒരു style argument-ഉ ഒഴിഞ്ഞ് ഒരു standard ആകുന്നു. ടൂൾ പൂർണ്ണമായും ബ്രൗസറിൽ run ചെയ്യുന്നു, query page വിടുന്നില്ല, sql-formatter npm package power ചെയ്യുന്ന dialect-aware tokenizer rewrite ചെയ്യുന്നു.