我正在我的jupyter笔记本中使用AWS雅典娜运行一个SQL查询,如下所示。它涉及计算时间戳之间的差异,如下所示。
query_demog = """
select ad.subject_id, ad.hadm_id, i.icustay_id ,
date_diff('second', timestamp '1970-01-01 00:00:00', ad.admittime) as admittime,
date_diff('second', timestamp '1970-01-01 00:00:00', ad.dischtime) as dischtime,
ROW_NUMBER() over (partition by ad.subject_id order by i.intime asc) as adm_order,
case when i.first_careunit='NICU' then 5
when i.first_careunit='SICU' then 2
when i.first_careunit='CSRU' then 4
when i.first_careunit='CCU' then 6
when i.first_careunit='MICU' then 1
when i.first_careunit='TSICU' then 3
end as unit,
date_diff('second', timestamp '1970-01-01 00:00:00', i.intime) as intime,
date_diff('second', timestamp '1970-01-01 00:00:00', i.outtime) as outtime,
i.los,
from mimiciii.admissions ad,
mimiciii.icustays i,
mimiciii.patients p
where ad.hadm_id=i.hadm_id and p.subject_id=i.subject_id
order by subject_id asc, intime asc
"""效果很好。现在,当我包含另一行具有类似时间戳差异时,我会得到一个错误。
query_demog = """
select ad.subject_id, ad.hadm_id, i.icustay_id ,date_diff('second', timestamp '1970-01-01 00:00:00', ad.admittime) as admittime, date_diff('second', timestamp '1970-01-01 00:00:00', ad.dischtime) as dischtime, ROW_NUMBER() over (partition by ad.subject_id order by i.intime asc) as adm_order, case when i.first_careunit='NICU' then 5 when i.first_careunit='SICU' then 2 when i.first_careunit='CSRU' then 4 when i.first_careunit='CCU' then 6 when i.first_careunit='MICU' then 1 when i.first_careunit='TSICU' then 3 end as unit, date_diff('second', timestamp '1970-01-01 00:00:00', i.intime) as intime, date_diff('second', timestamp '1970-01-01 00:00:00', i.outtime) as outtime, i.los,
EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age
from mimiciii.admissions ad, mimiciii.icustays i, mimiciii.patients p
where ad.hadm_id=i.hadm_id and p.subject_id=i.subject_id
order by subject_id asc, intime asc
"""包含行EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age将创建一个错误,如下所示。
调用StartQueryExecution操作时发生错误(InvalidRequestException):第3行:37:不匹配的输入“:”期望{'.',‘’),‘'[’‘,'AT’‘,'+',’‘,'*','%',’%‘}无法回滚
我不知道为什么包含EXTRACT(EPOCH FROM (i.intime-p.dob)::INTERVAL)/86400 as age会产生错误
发布于 2020-01-29 08:28:21
内置的to_unixtime()应该可以工作:
to_unixtime(i.intime-p.dob)/86400 as agehttps://stackoverflow.com/questions/59963000
复制相似问题