开发者

convert sqlite query to postgres

开发者 https://www.devze.com 2023-04-02 07:44 出处:网络
I have the following query from sqlite and would like to convert it to postgres: select date(date, \'-\'||strfti开发者_如何学Cme(\'%w\', date)||\' days\') as date from msgs group by date order by dat

I have the following query from sqlite and would like to convert it to postgres:

select date(date, '-'||strfti开发者_如何学Cme('%w', date)||' days') as date from msgs group by date order by date asc limit 10;

update:

I believe this could do it: select (date::date - extract(dow from date)::int)::date as d from msgs group by d order by d asc limit 10;


That depends. Is it more important to group by date and then mangle the output to the format you want? Or are you better off grouping by date(date, '-'||strftime('%w', date)||' days')? If you wanna group by just date, then do something like

select date(x.date, '-'||strftime('%w', x.date)||' days') from (select date from msgs group by date order by date asc limit 10) as x;

Otherwise group by date(date, '-'||strftime('%w', date)||' days') and you're done.

0

精彩评论

暂无评论...
验证码 换一张
取 消