Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

jackc/sqlfmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d576133 · Dec 21, 2019
Oct 24, 2017
Dec 18, 2019
Jul 25, 2015
Jul 10, 2015
May 13, 2017
Oct 24, 2017
Jul 25, 2015
Sep 30, 2015
Aug 29, 2015
May 13, 2017
May 13, 2017
Dec 18, 2019
Dec 18, 2019
Aug 29, 2015
Aug 29, 2015

Repository files navigation

sqlfmt

Installation

$ go get github.com/jackc/sqlfmt/...
$ which sqlfmt
$GOPATH/bin/sqlfmt

Usage

  • You can either:

    • Provide the path to one or more SQL files as command line arguments:

      $ sqlfmt testdata/select_where.input.sql
      select
        foo,
        bar
      from
        baz
      where
        foo > 5
        and bar < 2
    • Or, directly provide the SQL string via stdin:

      $ echo "select * from users" | sqlfmt
      select
        *
      from
        users
      $ sqlfmt < testdata/like.input.sql
      select
        foo,
        bar
      from
        baz
      where
        foo like 'abd%'
        or foo like 'ada%' escape '!'
        or foo not like 'abd%'
        or foo not like 'ada%' escape '!'
        or foo ilike 'efg%'
        or foo ilike 'ada%' escape '!'
        or foo not ilike 'efg%'
        or foo not ilike 'ada%' escape '!'
  • View testdata for more examples.