Ever needed to check if a date matches another within a certain range? If you need to trim to hours, minutes or seconds the date_trunc function in postgres does the job just fine. How about if you need to trunc to 10s? The following function should be of assistance:

<pre lang="sql">create function date_trunc_x(timestamp with time zone, numeric) returns text AS $$
    select substring(extract('hour' from $1)||':'||extract('minute' from $1)||':'||(extract('second' from $1)::int/$2) from 0 for 8)
$$ LANGUAGE SQL;

In can be used as in the following example:

<pre lang="sql">
select * from position where date_trunc_x(update_time, 10) in (select date_trunc_x(update_time, 10) from event_msg_x where event_fk = 31 and cp = '4' and trackcode = '117') and trackCode = '117'