X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3CB849DC81A for ; Tue, 27 Dec 2005 14:57:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70661-02 for ; Tue, 27 Dec 2005 14:57:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from fep05.ttnet.net.tr (mail.ttnet.net.tr [212.175.13.129]) by postgresql.org (Postfix) with ESMTP id 4A2899DCA30 for ; Tue, 27 Dec 2005 14:57:23 -0400 (AST) Received: from (192.168.8.105) by AVGW-I-1.ttnet.net.tr via smtp id 735d_40d481b6_770a_11da_8eb6_001422175f0e; Tue, 27 Dec 2005 20:54:49 +0200 Received: from alamut ([85.97.162.227]) by fep05.ttnet.net.tr with ESMTP id <20051227185503.QJNF26646.fep05.ttnet.net.tr@alamut>; Tue, 27 Dec 2005 20:55:03 +0200 Date: Tue, 27 Dec 2005 20:53:51 +0200 From: Volkan YAZICI To: "Mavinakuli, Prasanna (STSD)" Cc: pgsql-interfaces@postgresql.org Subject: Re: Convertion of date/time binary format to text format Message-ID: <20051227185351.GA546@alamut> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="KsGdsel6WgEHnImy" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i X-NAI-Spam-Rules: 1 Rules triggered BAYES_01=-1.2 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.255 required=5 tests=[AWL=-0.544, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44, DNS_FROM_RFC_WHOIS=0.879, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 2.255 X-Spam-Level: ** X-Archive-Number: 200512/46 X-Sequence-Number: 5914 --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Dec 23 12:25, Mavinakuli, Prasanna (STSD) wrote: > So how can I get the ASCII format/Text format from that binary > format. > > Please get me the steps to convert timestamp column which is of > binary mode to TEXT/ASCII mode I attached an example program which answers your question. Hope this helps. (I skipped byte order conversions in my example for simplicity. Don't forget 'em in your own program for portability.) Regards. -- "We are the middle children of history, raised by television to believe that someday we'll be millionaires and movie stars and rock stars, but we won't. And we're just learning this fact," Tyler said. "So don't fuck with us." --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="libpq_binary_date.c" #include #include #include "libpq-fe.h" void SmartQuit(PGconn *conn) { int stat = 0; if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "C> %s", PQerrorMessage(conn)); stat = 1; } PQfinish(conn); exit(stat); } int main(void) { PGconn *conn; PGresult *res; char *vcol0, *vcol1; int lcol0, lcol1; conn = PQconnectdb("dbname=test"); if (PQstatus(conn) != CONNECTION_OK) SmartQuit(conn); PQclear(PQexec(conn, "BEGIN;" "CREATE TEMP TABLE t_tmp (col0 text, col1 date);" "INSERT INTO t_tmp VALUES ('example text', now()::date)")); /* Give attention to ::text casting for date column. */ res = PQexecParams(conn, "SELECT col0, col1::text FROM t_tmp", 0, NULL, NULL, NULL, NULL, 1); if (PQresultStatus(res) != PGRES_TUPLES_OK) { fprintf(stderr, "R> %s", PQresultErrorMessage(res)); PQclear(res); SmartQuit(conn); } vcol0 = PQgetvalue(res, 0, 0); lcol0 = PQgetlength(res, 0, 0); vcol1 = PQgetvalue(res, 0, 1); lcol1 = PQgetlength(res, 0, 1); printf("(%d bytes) '%s'\n", lcol0, vcol0); printf("(%d bytes) '%s'\n", lcol1, vcol1); /* * (12 bytes) 'example text' * (10 bytes) '2005-12-27' */ PQclear(res); PQclear(PQexec(conn, "ROLLBACK")); PQfinish(conn); return 0; } --KsGdsel6WgEHnImy--