Re: ODBC Layer and the now() function

Lists: pgsql-general
From: Byrne Kevin-kbyrne01 <kbyrne01(at)motorola(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: ODBC Layer and the now() function
Date: 2005-12-05 10:33:00
Message-ID: 496E31A690F7D311B93C0008C789494C1241DA14@zei02exm01.cork.cig.mot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Has anyone seen any strange behaviour as regards the now() function when accessing a db via odbc layer. The behaviour I have seen (which I have mentioned in pervious post) is as follows:

I have a trigger set up on a db - when a row is added to a certain table (say Table A) in my db the trigger calls a function and then the function enters another line in a related table (say Table B). Here's the problem, the first addition to Table A may shows the time of the addition as, for example 19:01:53. This is correct. The second addition, triggered by the first additon, shows a time of say 19:01:10! The addition of the row to Table B uses the now() function to determine the time the new row is added to the table. This should in theory match the time (to within a few milliseconds at least) the first row was added, since the trigger is immediate. However, I am seeing major time differences?

For the first table, Table A, timestamp is obtained using timeofday. As mentioned the second table uses now(). There is a possibility that these two times will differ slightly. However, I do not understand why the time of entry into the second table could be earlier than the first table!? i.e.

Moserver receives the event - timestamps it as 't1'
-- time lapse before moserver computes the transaction and gives it to odbc.
Txn_begin- now() gets frozen to 't2'
Insert - now() should put it as 't2'
Txn_end()- done.

So firstly t2 should always be > t1 and the difference could be a few seconds but I found sometimes t2 < t1!..


From: Pandurangan R S <pandurangan(dot)r(dot)s(at)gmail(dot)com>
To: Byrne Kevin-kbyrne01 <kbyrne01(at)motorola(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ODBC Layer and the now() function
Date: 2005-12-05 13:59:07
Message-ID: 5e744e3d0512050559t636d71b0hf489ec82b3a515@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi,

I hope the following link will help you.

http://www.postgresql.org/docs/8.0/static/plpgsql-expressions.html

On 12/5/05, Byrne Kevin-kbyrne01 <kbyrne01(at)motorola(dot)com> wrote:
>
> Has anyone seen any strange behaviour as regards the now() function when
> accessing a db via odbc layer. The behaviour I have seen (which I have
> mentioned in pervious post) is as follows:
>
> I have a trigger set up on a db - when a row is added to a certain table
> (say Table A) in my db the trigger calls a function and then the function
> enters another line in a related table (say Table B). Here's the problem,
> the first addition to Table A may shows the time of the addition as, for
> example 19:01:53. This is correct. The second addition, triggered by the
> first additon, shows a time of say 19:01:10! The addition of the row to
> Table B uses the now() function to determine the time the new row is added
> to the table. This should in theory match the time (to within a few
> milliseconds at least) the first row was added, since the trigger is
> immediate. However, I am seeing major time differences?
>
> For the first table, Table A, timestamp is obtained using timeofday. As
> mentioned the second table uses now(). There is a possibility that these two
> times will differ slightly. However, I do not understand why the time of
> entry into the second table could be earlier than the first table!? i.e.
>
> Moserver receives the event - timestamps it as 't1'
> -- time lapse before moserver computes the transaction and gives it to
> odbc.
> Txn_begin- now() gets frozen to 't2'
> Insert - now() should put it as 't2'
> Txn_end()- done.
>
> So firstly t2 should always be > t1 and the difference could be a few
> seconds but I found sometimes t2 < t1!..
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Byrne Kevin-kbyrne01 <kbyrne01(at)motorola(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ODBC Layer and the now() function
Date: 2005-12-05 14:59:22
Message-ID: 29463.1133794762@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Byrne Kevin-kbyrne01 <kbyrne01(at)motorola(dot)com> writes:
> Moserver receives the event - timestamps it as 't1'
> -- time lapse before moserver computes the transaction and gives it to odbc.
> Txn_begin- now() gets frozen to 't2'
> Insert - now() should put it as 't2'
> Txn_end()- done.

> So firstly t2 should always be > t1 and the difference could be a few seconds but I found sometimes t2 < t1!..

I'd wonder about clock skew between the machine that's running
"moserver" and the machine running Postgres.

Another possibility is that the "transaction begin" doesn't happen when
you think it does. Sometimes driver-level code like ODBC will issue
BEGIN behind your back ...

regards, tom lane