PostgreSQL error code
PostgreSQL error 42846
42846 is the SQLSTATE PostgreSQL reports for cannot coerce, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42846 |
|---|---|
| Condition name | cannot_coerce |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
There is no cast from a timestamp to an integer, since it isn’t clear which number you mean. extract(epoch ...) gives the seconds since 1970. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
SELECT id, created_at::int FROM orders;
SELECT id, extract(epoch FROM created_at)::bigint AS created_epoch FROM orders;