This should never fail (I simplified a bit):
WHERE status_code IN ('30000','30005')
AND expiration > now()
PostgreSQL can compare date
and timestamp
(with or without time zone) automatically. If one is a date
it is cast to timestamp
automatically (0:0 hours).
The error message tells a different story. You are actually trying to input a date
with invalid syntax.
I wrote a detailed answer about handling of timestamps with or without time zone in PostgreSQL recently - if that should the issue:
As it turns out, expiration
is a text
column. You need to cast it to date
or timestamp
(whichever fits your need). If it is in a valid format:
...
AND expiration::timestamptz > now()
If you have invalid strings like 'No End Date' in that text column, you need to clean the source or treat those specially in a CASE
construct:
...
AND CASE WHEN expiration::text = 'No End Date' THEN 'infinity'::timestamp
WHEN expiration::text = 'foo' THEN '-infinity'::timestamp
ELSE expiration::timestamp
END > now()
The manual about the special value infinity
.
The cast to text (::text
) is redundant with text
, but makes the expression work with date
/ timestamp
values as well.
If the format of the time stamp literal can be ambiguous, use to_date()
or to_timestamp()
and define the format explicitly:
to_date('07/08/2013', 'DD/MM/YYYY')
Use the AT TIME ZONE
construct if expiration
is supposed to be a local timestamp of another time zone:
expiration::timestamp AT TIME ZONE 'UTC' -- desired time zone here
If expiration
is in ambiguous / non-standard format, use to_timestamp()
:
to_timestamp(expiration::text, 'yyyy-mm-dd')
Select A.status,count (A.record_id),sum(A.hits)
from
(Select distinct status,record_id,hits from YourTable) A
group by A.status
Best Answer
Assuming
updatedAt
stores the transaction timestamp as reported bynow()
orCURRENT_TIMESTAMP
. See:Then yes,
xmin
behaves like a simple sequence, basically.But you may want to look at
cmin
additionally. The manual:Related:
And, subtransactions (incurring a
SAVEPOINT
) may very well interfere with your plans, as those advance the transaction ID (and hence thexmin
of rows written after that) within the same transaction, while the transaction timestamp stays the same.So, that's a YES to the question in the title. It is possible to have xid before and after wrap around with the same timestamp.
There are various ways subtransactions may get involved:
EXCEPTION
clauseON_ERROR_ROLLBACK
setting in PostgresRelated:
How to view tuples changed in a PostgreSQL transaction?
Related discussion on ppgsql-general