Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U2jZn-0004YQ-3V for pgsql-jdbc@arkaria.postgresql.org; Tue, 05 Feb 2013 14:32:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U2jZl-0007pa-ON for pgsql-jdbc@arkaria.postgresql.org; Tue, 05 Feb 2013 14:32:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U2bNG-0000ld-7u for pgsql-jdbc@postgresql.org; Tue, 05 Feb 2013 05:47:18 +0000 Received: from moutng.kundenserver.de ([212.227.17.10]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U2bNC-0006l0-GB for pgsql-jdbc@postgresql.org; Tue, 05 Feb 2013 05:47:17 +0000 Received: from [192.168.0.10] (node-730.pool-1-4.dynamic.totbb.net [1.4.163.220]) by mrelayeu.kundenserver.de (node=mrbap3) with ESMTP (Nemesis) id 0MXp03-1UQbsG3UTH-00Wpvy; Tue, 05 Feb 2013 06:47:13 +0100 Message-ID: <1360043227.14635.9.camel@localhost> Subject: Timestamp vs. Java Date/Timestamp From: Andreas Reichel To: pgsql-jdbc@postgresql.org Date: Tue, 05 Feb 2013 05:47:07 +0000 Content-Type: text/plain; charset="us-ascii" X-Mailer: Evolution 3.6.3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:6m1DlhNCNmnrl5NfAVOaXAJ0d9DO4Jkd7xt46GHIpgE h3LbHxNOd1sQC6zmqhrWxRYjwkPo3qerg8nEDVjml12sfRK0Rf srGTkXA9YA5t1vWJB6fOluY4lWSTOPsFU4c/Id17CSEbVRPgWj /BiDxMFIGO0PBrHmxFaZX63xHj6RdBsQRVxJajIuV3PgYXsbqj 1Wv1UlfZXgxCfqX/3dLe0nQPA2Fevj4IbIqq7Gq4Lf+TZ0bE4r 69Utk6MsBkrp33HOFSd+mFZGey7m7tRDYQoa9l1cmaKNaeACiq JZ6kTbdqXy0gUZX22cyZ0rJ+8z+eCMPDfOHE4FHSeduEFZMgye Vdg7RfRQ2vZPp+rJcf1fVpsmmqjOZTvAuHS/G7lQd X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Dear List, the last day I had a hard time figuring out how to hand over timestamps using prepared statements. The table looks like this: trader=# \d trader.tickdata Table "trader.tickdata" Column | Type | Modifiers -------------------+-----------------------------+----------- id_instrument | smallint | not null id_stock_exchange | smallint | not null timestamp | timestamp without time zone | not null price | double precision | not null Now I would like to retrieve ticks using a prepared statement like this: -- GET TICKDATA select t1.id_instrument, t1.id_stock_exchange, t1."timestamp", t1.price, coalesce(t2.quantity,0) quantity from trader.tickdata t1 left join trader.volumedata t2 ON (t1.id_instrument=t2.id_instrument AND t1.id_stock_exchange=t2.id_stock_exchange AND t1."timestamp"=t2."timestamp") where t1.id_instrument= ? AND t1.id_stock_exchange= ? --careful with TIMEZONE here! AND t1."timestamp">= ? AND t1."timestamp"<= ? ORDER BY t1."timestamp" ASC; If I hand over java.util.Date or java.sql.Date or java.sql.Timestamp the query will be executed but returns the wrong number of records; However, if I change the query into: -- GET TICKDATA select t1.id_instrument, t1.id_stock_exchange, t1."timestamp", t1.price, coalesce(t2.quantity,0) quantity from trader.tickdata t1 left join trader.volumedata t2 ON (t1.id_instrument=t2.id_instrument AND t1.id_stock_exchange=t2.id_stock_exchange AND t1."timestamp"=t2."timestamp") where t1.id_instrument= ? AND t1.id_stock_exchange= ? --careful with TIMEZONE here! AND t1."timestamp">= cast(? as timestamp) AND t1."timestamp"<= cast(? as timestamp) ORDER BY t1."timestamp" ASC; and hand over a formated date "yyyy-MM-dd HH:mm:ss" it works correctly. Now I have on simple questions please: What is the correct way to hand over a Java Date parameter (avoiding the double String manipulation)? Thank you and best regards! Andreas -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc