Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

DB.literal :symbol should not quote "symbol" #2119

Closed
felipeAH opened this issue Jan 14, 2024 · 4 comments
Closed

DB.literal :symbol should not quote "symbol" #2119

felipeAH opened this issue Jan 14, 2024 · 4 comments

Comments

@felipeAH
Copy link

felipeAH commented Jan 14, 2024

Complete Description of Issue

Hi,
trying to create a table with this code into postgres database

DB.create_table! :test do
  DateTime :date, default: :CURRENT_DATETIME
end

results in an error because CURRENT_DATETIME gets quoted, so digging into the source code I come to

Proxy the literal call to the dataset.

#
#   DB.literal(1)   # 1
#   DB.literal(:a)  # a
#   DB.literal('a') # 'a'
def literal(v)
  schema_utility_dataset.literal(v)
end

and with my poor ruby skills is the farthest I could get.
Could't find where #literal gets implemented. ( can you please enlighten me? )
Sorry for my bad english.

Simplest Possible Self-Contained Example Showing the Bug

DB.literal :symbol => "\"symbol\"" (should be "symbol")

Full Backtrace of Exception (if any)

No response

SQL Log (if any)

No response

Ruby Version

ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]

Sequel Version

Tested with 5.63.0 and 5.76.0

@felipeAH felipeAH changed the title DB.literal :symbol shold not quote "symbol" DB.literal :symbol should not quote "symbol" Jan 14, 2024
@jeremyevans
Copy link
Owner

This is expected behavior, as Sequel quotes identifiers by default (to handle symbols that are also SQL keywords, among other reasons). Use Sequel.lit('CURRENT_DATETIME'). If you don't want identifiers quoted by default, you can use the identifier_mangling extension and set DB.quote_identifiers = false.

@felipeAH
Copy link
Author

felipeAH commented Jan 14, 2024

Thank you.

Anyway the comments in

#
#   DB.literal(1)   # 1
#   DB.literal(:a)  # a
#   DB.literal('a') # 'a'
def literal(v)
  schema_utility_dataset.literal(v)
end

are missleading ... wrong IMHO.

Regards.

@jeremyevans
Copy link
Owner

Thank you.

Anyway the comments in

#
#   DB.literal(1)   # 1
#   DB.literal(:a)  # a
#   DB.literal('a') # 'a'
def literal(v)
  schema_utility_dataset.literal(v)
end

are missleading ... wrong IMHO.

Well, they aren't necessarily wrong. Some adapters disable identifier quoting, and the actual literal value depends on the adapter. In most example SQL examples in the Sequel documentation, identifiers are shown unquoted. However, I don't have an issue expanding this example.

@jeremyevans
Copy link
Owner

Updated the documentation in 150e754

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants