Skip to content

Commit

Permalink
add examples of :alias with :group-by
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Corfield <sean@corfield.org>
  • Loading branch information
seancorfield committed Jan 28, 2025
1 parent 44ca426 commit c295db4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/clause-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,11 @@ user=> (sql/format '{select (*) from (table)
["SELECT * FROM table GROUP BY status, YEAR(created_date)"]
```

You can `GROUP BY` expressions, column names (`:col1`), or table and column (`:table.col1`),
or aliases (`:some.alias`). Since there is ambiguity between the formatting
of those, you can use the special syntax `[:alias :some.thing]` to tell
HoneySQL to treat `:some.thing` as an alias instead of a table/column name.

## having

The `:having` clause works identically to `:where` above
Expand Down
8 changes: 8 additions & 0 deletions doc/special-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ and strings.
:from :b
:order-by [[[:alias :'some-alias]]]})
;;=> ["SELECT column_name AS \"some-alias\" FROM b ORDER BY \"some-alias\" ASC"]
(sql/format {:select [[:column-name "some-alias"]]
:from :b
:group-by [[:alias "some-alias"]]})
;;=> ["SELECT column_name AS \"some-alias\" FROM b GROUP BY \"some-alias\""]
(sql/format {:select [[:column-name "some-alias"]]
:from :b
:group-by [[:alias :'some-alias]]})
;;=> ["SELECT column_name AS \"some-alias\" FROM b GROUP BY \"some-alias\""]
```

## array
Expand Down

0 comments on commit c295db4

Please # to comment.