is there a way to add the same unix timestamp to all the rows in a select statement in PostgreSQL?
The purpose is to have the same value for all the rows – regards how long it runs.
When running the following query – if the query takes long (couple of seconds for millions of rows) then some rows will have a different timestamp.
select id, (extract(epoch from now())) as queryId from books;
Edit:
This is actually works
2
Answers
Why don’t you generate the timestamp first and then select it for all the rows from the books table.
Your
SELECT
works as is.now()
is a stable function (volatilitySTABLE
). Meaning, it’s outcome never changes within the sameSELECT
statement. See: