简体   繁体   中英

How to parse today's date into a parameter

I want to create a parameter with today's date in order to add it in my queries in an sql script. I tried the below:

${var:id_date} =  from_timestamp(date_trunc('second', now()),'yyyyMMdd');

But I am facing the below issue.

ParseException: Syntax error in line 1:undefined: ${var:id_date} = select from... ^ Encountered: IDENTIFIER Expected: ALTER, COMMENT, COMPUTE, COPY, CREATE, DELETE, DESCRIBE, DROP, EXPLAIN, GRANT, INSERT, INVALIDATE, LOAD, REFRESH, REVOKE, SELECT, SET, SHOW, TRUNCATE, UPDATE, UPSERT, USE, VALUES, WITH CAUSED BY: Exception: Syntax error

When setting variable use set var:id_date=...;

set var:id_date=from_timestamp(date_trunc('second', now()),'yyyyMMdd');

    select * from mytable where id_date=${var:id_date};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM