skip to Main Content

I am facing an issue to update the dataset with data type is date in Condition

Script:

UPDATE blse
   SET employment = 2066.3
 WHERE date = (i am not sure how)
   AND industry = 'Total Nonfarm'
   AND state = 'Alabama'
;

2

Answers


  1. The Date type formate is YYYY-MM-DD

    Example:

    SELECT * FROM posts WHERE date = "1982-02-22";
    

    so the command must be like

    UPDATE blse 
    SET employment = 2066.3 
    WHERE 
        date = "2022-09-22" AND 
        industry = 'Total Nonfarm' AND 
        state = 'Alabama';
    
    Login or Signup to reply.
  2. I would recommend to use to_date() if you are casting from a string to accommodate a specific format. Example:

    SELECT to_date('2000/JUN','YYYY/MON'); -- ok
    SELECT '2000/JUN'::date; -- error
    

    Check doc on to_date function:
    https://www.postgresql.org/docs/current/functions-formatting.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search