Retrieving timestamp data

Lists: pgsql-interfaces
From: "::Willi the One::" <sonic_and_tails2000(at)yahoo(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Retrieving timestamp data
Date: 2007-03-04 15:23:10
Message-ID: 20070304152310.95205.qmail@web36709.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

In the documentation, it says that PQgetvalue()
returns string values for strings and "the value is in
the binary representation determined by the data
type’s typsend and typreceive functions." The problem
is, where's the typsend and typrecieve located? I know
that it's not in libpq, but I saw libpgtypes somewhere
in the postgres directory and saw that there are
PGTYPE-related functions but I can't find the typsend.

For example, if I want to retrieve a timestamp data,
how would I do it? Will it return as a string when I
call PQgetvalue()? What about other types such Points
or inet types?

Thanks in advance.

Life is too short for dial-up.


____________________________________________________________________________________
Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
http://farechase.yahoo.com/promo-generic-14795097


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "::Willi the One::" <sonic_and_tails2000(at)yahoo(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Retrieving timestamp data
Date: 2007-03-04 17:23:55
Message-ID: 20070304172355.GA38897@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

On Sun, Mar 04, 2007 at 07:23:10AM -0800, ::Willi the One:: wrote:
> In the documentation, it says that PQgetvalue()
> returns string values for strings and "the value is in
> the binary representation determined by the data
> type’s typsend and typreceive functions."

You've omitted part of what the documentation says. The complete
text is:

For data in text format, the value returned by PQgetvalue is a
null-terminated character string representation of the field
value. For data in binary format, the value is in the binary
representation determined by the data type's typsend and typreceive
functions.

> The problem is, where's the typsend and typrecieve located?

In the backend. You can find out which functions they are by
querying pg_type, and you can learn more about the functions
themselves by querying pg_proc and by examining the source code.
But you should only need to do this if you need query results in
binary format. Do you?

> For example, if I want to retrieve a timestamp data,
> how would I do it? Will it return as a string when I
> call PQgetvalue()? What about other types such Points
> or inet types?

Unless you request results in binary format all values will be
returned as text strings. What happened when you tried it? Are
you requesting results in binary format?

--
Michael Fuhr


From: "::Willi the One::" <sonic_and_tails2000(at)yahoo(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Retrieving timestamp data
Date: 2007-03-04 17:54:59
Message-ID: 20070304175459.82626.qmail@web36710.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces


>
> Unless you request results in binary format all
> values will be
> returned as text strings. What happened when you
> tried it? Are
> you requesting results in binary format?
>

So all data are returned as string unless I say so?
I'll try expermenting this a bit.

by the way, are there any site containing tutorials on
libpq?

Life is too short for dial-up.


____________________________________________________________________________________
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097


From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "::Willi the One::" <sonic_and_tails2000(at)yahoo(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Retrieving timestamp data
Date: 2007-03-04 19:17:18
Message-ID: 20070304191718.GA39524@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

On Sun, Mar 04, 2007 at 09:54:59AM -0800, ::Willi the One:: wrote:
> > Unless you request results in binary format all values will be
> > returned as text strings. What happened when you tried it? Are
> > you requesting results in binary format?
>
> So all data are returned as string unless I say so?

PQexecParams() and PQexecPrepared() take an argument that specifies
the result format so you have to indicate which format you want.
PQexec() doesn't take a format argument so it returns results in
text format unless you're fetching from a binary cursor.

> by the way, are there any site containing tutorials on
> libpq?

Probably; Google is your friend :-)

--
Michael Fuhr