I need to converting a statement from MySQL to Postgres. The error is on this statement "INTERVAL $3 DAY". I am following a certain tutorial on building web apps using Go.
MySQL – insrt:= INSERT INTO snippets (title, content, created, expires) VALUES(?, ?, UTC_TIMESTAMP(), DATE_ADD(UTC_TIMESTAMP(), INTERVAL ? DAY))
My current statement Postgres insrt:= INSERT INTO snippets (title, content, created, expires) VALUES ($1, $2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + INTERVAL $3 DAY)
I tried changing the statement using chat GPT but I stuck there.
"ERROR: syntax error at or near "$3" (SQLSTATE 42601)"
2
Answers
The documentation says the argument to
interval
is a string. You could try:Reading a tutorial like Go: working with PostgreSQL might be helpful.
According to chat GPT 4 with my prompting I get this code snippet below, I have tried to test it and it worked, according to my GPT result gives 10 days ahead of its time as expected.
Another approach of mine incase interval is unknown;
Hope it helps