Postgresql - select something where date = “01/01/11”

前端 未结 2 916
孤独总比滥情好
孤独总比滥情好 2021-01-31 07:13

I have a datetime field in my Postgresql, named \"dt\". I\'d like to do something like

SELECT * FROM myTable WHERE extract (date from dt) = \'01/01/11\'
         


        
2条回答
  •  无人共我
    2021-01-31 08:02

    I think you want to cast your dt to a date and fix the format of your date literal:

    SELECT *
    FROM table
    WHERE dt::date = '2011-01-01' -- This should be ISO-8601 format, YYYY-MM-DD
    

    Or the standard version:

    SELECT *
    FROM table
    WHERE CAST(dt AS DATE) = '2011-01-01' -- This should be ISO-8601 format, YYYY-MM-DD
    

    The extract function doesn't understand "date" and it returns a number.

提交回复
热议问题