Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MS SQL table hints in FROM clause (e.g. NOLOCK) #522

Closed
Prometheus77 opened this issue Jan 10, 2024 · 1 comment
Closed

MS SQL table hints in FROM clause (e.g. NOLOCK) #522

Prometheus77 opened this issue Jan 10, 2024 · 1 comment
Assignees
Labels
enhancement needs analysis I need to think about this!

Comments

@Prometheus77
Copy link

As an MS SQL user, I want to be able to add table hints to FROM clauses natively in HoneySQL.

For example, the query:

SELECT * FROM mytable WITH (NOLOCK)

can be approximated by HoneySQL

(sql/format {:select :*
             :from [[:mytable [:t [:raw "WITH (NOLOCK)"]]]]})

which yields

[SELECT * FROM mytable AS t WITH (NOLOCK)]

however, this suffers from two issues:

  1. It requires the creation of a table alias (t)
  2. It requires using the :raw tag rather than supporting it natively

A more elegant solution would look something like

(sql/format {:select :*
             :from [[:table [:hints :nolock]]]})

For reference:

@seancorfield seancorfield self-assigned this Jan 10, 2024
@seancorfield seancorfield added enhancement needs analysis I need to think about this! labels Jan 10, 2024
seancorfield added a commit that referenced this issue Jan 14, 2024
Signed-off-by: Sean Corfield <sean@corfield.org>
@seancorfield
Copy link
Owner

I went with metadata for this:

(sql/format {:select :*
             :from [^:nolock [:table]]})

Works with all the :join clauses too.

Right now, it's hardcoded to SQL Server's WITH (...) format. If other dialects need something different -- and people ask for it -- I'll make it more flexible.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement needs analysis I need to think about this!
Projects
None yet
Development

No branches or pull requests

2 participants