Pg_query as timestamp

I get 0 results if I query the timestamp column for records containing 2017 (or any other year).

The data in w_presse_erscheinung is "timestamp without timezone" and looks like this: 2017-06-01 00:00:00

I'm guessing there is something wrong with the LIKE part of the request ...

My request looks like this:

        $result = pg_query("
        SELECT 
        name, 
        w_presse_link, 
        w_presse_erscheinung, 
        w_presse_quelle, 
        description 

        FROM adempiere.w_presse 
        WHERE isactive ='Y' 
        AND description='PS' AND w_presse_erscheinung LIKE '%2017%'
        ORDER BY w_presse_erscheinung 
        DESC
        ")

      

+3


source to share


2 answers


Instead of relying on string conversions, you can explicitly extract the year from the timestamp:



EXTRACT(YEAR FROM w_presse_erscheinung) = 2017

      

+2


source


You cannot use for example on a timestamp field. Either output the timestamp field to varchar, or use the extract function, or use the extract function to match the year from the field.



+1


source







All Articles