X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 873A0D1B18C for ; Sun, 11 Jul 2004 20:53:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18096-05 for ; Sun, 11 Jul 2004 23:53:34 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id A4B73D1B181 for ; Sun, 11 Jul 2004 20:53:30 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1Bjo5Q-0002GC-00; Mon, 12 Jul 2004 11:50:24 +1200 Message-ID: <40F1D220.4010209@opencloud.com> Date: Mon, 12 Jul 2004 11:49:52 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Greg Markham Cc: pgsql-jdbc@postgresql.org Subject: Re: Timestamp Question References: <40F012E4.3000001@markhamdirect.com> <40F15284.2090905@opencloud.com> <40F1A903.9040000@markhamdirect.com> In-Reply-To: <40F1A903.9040000@markhamdirect.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200407/100 X-Sequence-Number: 10484 Greg Markham wrote: > Oliver Jowett wrote: > >> Greg Markham wrote: >> >>> I have searched the archives and not found and answer to this question: >>> >>> I am trying to use a Java Timestamp object to create a Postgresql >>> Timestamp(6) field. I can insert a Timestamp but it only goes to the >>> millisecond(2004-07-10 12:59:59.123) I need it to the microsecond >>> (2004-07-10 12:59:59.123456). Is there a way to do this? >> >> >> >> From a quick look at the driver code, it appears to support nanosecond >> precision in Timestamps. >> >> What exactly is the problem you see? Can you provide a testcase? >> >> -O >> > Timestamp myTs = new Timestamp(System.currentTimeMillis()); Ah, Dave was right then, you are trying to insert the current time :) I thought you were dealing with some time data that actually had sub-millisecond precision. > When I create a timestamp using the system.currentTimeMillis it just > doesn't create a timestamp that has the precision I want. Right -- as the name suggests, System.currentTimeMillis() counts in milliseconds. > I want the > timestamp out past the millisecond and out to the microsecond like > 2004-07-11 15:34:26.274123. How would I use the timestamp object to get > to that precision? Do I have to use a JNI call? Yes, you'll probably have to use JNI if you want to get sub-millisecond precision *in Java*. If you're only dealing with durations you might want to look at 1.5's (sorry, 5.0's .. sigh) System.nanoTime() -- it's not useful for absolute timestamps but you can compute durations from it just fine. Another alternative, as Dave Cramer suggested, is to use now() (server timestamp at start of transaction) or timeofday() (server timestamp at point of evaluation) in your SQL -- this will use the DB server timestamp to whatever precision is supported: > test=# select timeofday(); > timeofday > -------------------------------------- > Mon Jul 12 11:47:32.783796 2004 NZST > (1 row) -O