大家下午好
我对 PostgreSQL 很陌生,所以如果我的问题低于平均水平,请提前道歉。
我正在接收一些 csv flay 文件格式的数据,并且很好地插入到临时表中,以便我预览数据。我遇到的问题之一是数据字段存储为字符串值。例如,10Apr96 - 01Jan85
我编写了以下查询,看看是否可以将字符串分解并以日期格式重新连接在一起。
有没有更简单的方法来实现我正在做的事情?
select
concat(cast(substring(datetext,1,2) as varchar(2)),'/',case
when cast(substring(datetext,3,3) as varchar(3)) = 'Jan' then '01'
when cast(substring(datetext,3,3) as varchar(3)) = 'Feb' then '02'
when cast(substring(datetext,3,3) as varchar(3)) = 'Mar' then '03'
when cast(substring(datetext,3,3) as varchar(3)) = 'Apr' then '04'
when cast(substring(datetext,3,3) as varchar(3)) = 'May' then '05'
when cast(substring(datetext,3,3) as varchar(3)) = 'Jun' then '06'
when cast(substring(datetext,3,3) as varchar(3)) = 'Jul' then '07'
when cast(substring(datetext,3,3) as varchar(3)) = 'Aug' then '08'
when cast(substring(datetext,3,3) as varchar(3)) = 'Sep' then '09'
when cast(substring(datetext,3,3) as varchar(3)) = 'Oct' then '10'
when cast(substring(datetext,3,3) as varchar(3)) = 'Nov' then '11'
when cast(substring(datetext,3,3) as varchar(3)) = 'Dec' then '12'
end,'/',cast(substring(datetext,6,2) as varchar(2))) as dt
from tbl_loading_horses_tmp