In my Go code, I have this line of code:
rows, err := conn.Query(`
SELECT id, name, lang, deleted_at, read
FROM categories
WHERE deleted_at < NOW()
`)
When I run this, I get an error from PostgreSQL:
pq: function now() does not exist
(pq is the Go driver that I use)
Using CURRENT_TIMESTAMP
also provokes an error. It says that the column current_timestamp
does not exist. Using NOW()
directly in psql
(command line) does not provoke that error and everything works fine.
Any idea on why I can't use NOW()
nor CURRENT_TIMESTAMP
when sending a query from my Go app?
My right alt key on my keyboard got stuck without me noticing. That made me insert non-breakable spaces when pressing the space bar. PostgreSQL probably interpreted the non-breakable space as a character that is part of the function's name.
Inserting regular spaces instead solved the issue.
As far as I can see there is nothing wrong with your query. PostgreSQL can throw function not found at you also when the function actually exists but a different value type is expected.
The function now() returns timestamp with time zone. If the column deleted_at is not of the same type, you might need to cast either deleted_at or the output from now().