0

I have a query like the following

CAST(kokyaku1Information2.mail_jyushin as integer) as information2_mail_jyushin,
(date '$mytime' - INTERVAL 'information2_mail_jyushin' day) AS modified_date,

When run the query i get an error like invalid input syntax for type interval. I used another select field named information2_mail_jyushin before day.

1
  • 1
    I removed the inconsistent database tags. Please tag only with the database you are really using. Commented Nov 6, 2020 at 1:29

1 Answer 1

4

In Postgres, you would use interval arithmetics like this:

kyaku1Information2.mail_jyushin::int AS information2_mail_jyushin,
date '$mytime' 
    - kokyaku1Information2.mail_jyushin::int * interval '1 day' 
    AS modified_date

Note that concatenating variables in a SQL statement is bad practice, and opens up your code to SQL injection attacks. Instead, use parameters, as in:

$1::date 
    - kokyaku1Information2.mail_jyushin::int * interval '1 day' 
    AS modified_date
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.