Today I was scripting out some DB maintenance tasks on SQL Server, and was 
leveraging a query similar to:

SELECT DISTINCT create_ts
FROM #{table}
WHERE create_ts < DATEADD(MONTH, -2, GETDATE())

I initially thought "Hey, what does this look like with virtual row blocks, 
avoiding interpolation?

DB[:a_table].distinct.select(:create_ts)
  .where { create_ts < dateadd(month, -2, getdate()) }

I found that dateadd() was being parsed as a sql function call, but that 
getdate() was being treated as an identifier.

[17] pry(main)> DB[:a_table].distinct.select(:create_ts).where { create_ts 
< dateadd(month, -2, getdate()) }.sql
=> "SELECT DISTINCT [CREATE_TS] FROM [a_table] WHERE ([CREATE_TS] < 
dateadd([MONTH], -2, *[GETDATE]*))"

In this case, I was able to just use Ruby's `Date.today` rather than SQL's 
GETDATE(). I'm trying to improve my understanding of virtual row blocks, 
and was curious if there was a quick fix for this, or if it needs to drop 
into `Sequel.lit` or `Sequel.function` syntax.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/5af57e99-ebb2-45ab-ab36-88176000a938n%40googlegroups.com.

Reply via email to