Skip to content

Instantly share code, notes, and snippets.

@zerokarmaleft
Last active December 17, 2015 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerokarmaleft/5554349 to your computer and use it in GitHub Desktop.
Save zerokarmaleft/5554349 to your computer and use it in GitHub Desktop.
Sequel::DatabaseError: TinyTds::Error: Incorrect syntax near the keyword 'AS'. from /home/echo/.rvm/gems/ruby-2.0.0-p0/gems/sequel-3.47.0/lib/sequel/adapters/tinytds.rb:234:in `fields'
SELECT ([SUBJECTID], [NUM_BDI_TIMEPOINTS])
FROM [SUBJECTIDENTIFIERS]
INNER JOIN (SELECT [SUBJECTID], count([BDI_TP]) AS [NUM_BDI_TIMEPOINTS]
FROM [BDIS_OUTPUT]
WHERE ((([BDI_TP] COLLATE Latin1_General_CS_AS)
LIKE
(N'Y%' COLLATE Latin1_General_CS_AS) ESCAPE N'\\'))
GROUP BY [SUBJECTID]) AS [T1]
ON ([T1].[SUBJECTID] = [SUBJECTIDENTIFIERS].[SUBJECTID])
SELECT ([SUBJECTIDENTIFIERS].[SUBJECTID], [NUM_BDI_TIMEPOINTS])
FROM [SUBJECTIDENTIFIERS]
INNER JOIN (SELECT [SUBJECTID], count([BDI_TP]) AS [NUM_BDI_TIMEPOINTS]
FROM [BDIS_OUTPUT]
WHERE ([BDI_TP] LIKE 'Y%')
GROUP BY [SUBJECTID]) AS [T1]
ON ([T1].[SUBJECTID] = [SUBJECTIDENTIFIERS].[SUBJECTID])
require 'sequel'
Sequel::Model.db = Sequel.tinytds(host: "secretstuff",
database: "secretstuff",
username: "secretstuff",
password: "secretstuff")
class Subject < Sequel::Model(:subjectidentifiers)
set_primary_key :subjectid
one_to_many :bdimeasures, :key => :subjectid
def self.candidates()
bdi_counts = BDIMeasure.
select{[:subjectid, count(:bdi_tp).as(:num_bdi_timepoints)]}.
grep(:bdi_tp, 'Y%').
group_by(:subjectid)
subjects = Subject.
select([:subjectid, :num_bdi_timepoints]).
join(bdi_counts, :subjectid => :subjectid).
filter { num_bdi_timepoints >= 3 }
end
end
class BDIMeasure < Sequel::Model(:bdis_output)
set_primary_key [:subjectid, :bdi_tp]
many_to_one :subject, :key => :subjectid
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment