PostgreSQL: Select data with a like on timestamp field

后端 未结 5 1144
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 16:29

I am trying to select data from a table, using a \"like\" on date field \"date_checked\" (timestamp). But I have this error :

SQLSTATE[42883]: Undefined func         


        
5条回答
  •  情深已故
    2020-12-23 17:18

    It's all very well not "wanting to use" < and > with timestamps, but those operators can be converted into index scans, and a string-match... well, it can, but EWWWW.

    Well, the error is occurring because you need to explicitly convert the timestamp to a string before using a string operation on it, e.g.:

    date_checker::text LIKE '2011-01-%'
    

    and I suppose you could then create an index on (date_checker::text) and that expression would become an index scan but.... EWWWW.

提交回复
热议问题