Thread: Datatyp of a column

Datatyp of a column

From
Ishaya Bhatt
Date:
Hi,
     In the sorting code, I need to determine the datatype of my sort keys and call some code conditionally based on the datatype. Is there any way to determine the datatype of a column from the backend PostGreSQL code. is the datatype of the column available in the query plan? Any help on this would be very much appreciated.

Thanks,
Ishaya Bhatt.

Re: Datatyp of a column

From
Tom Lane
Date:
Ishaya Bhatt <ishayabhatt@gmail.com> writes:
>      In the sorting code, I need to determine the datatype of my sort keys
> and call some code conditionally based on the datatype. Is there any way to
> determine the datatype of a column from the *backend* PostGreSQL code. is
> the datatype of the column available in the query plan? Any help on this
> would be very much appreciated.

You really need to be more specific about where you need this information.
The "sorting code" certainly knows what datatypes it's working with ---
for example, in tuplesort.c there's a TupleDesc for the tuples passing
through the sort, and the column types are available from the per-column
atttypid fields of that.  But it's not clear if that's what you're talking
about.
        regards, tom lane



Re: Datatyp of a column

From
Ishaya Bhatt
Date:
<div dir="ltr">Yes!! Thats exactly what I was looking for !! Thanks :)<br /></div><div class="gmail_extra"><br /><br
/><divclass="gmail_quote">On Mon, Nov 11, 2013 at 7:58 PM, Tom Lane <span dir="ltr"><<a
href="mailto:tgl@sss.pgh.pa.us"target="_blank">tgl@sss.pgh.pa.us</a>></span> wrote:<br /><blockquote
class="gmail_quote"style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Ishaya Bhatt
<<ahref="mailto:ishayabhatt@gmail.com">ishayabhatt@gmail.com</a>> writes:<br /> >      In the sorting code, I
needto determine the datatype of my sort keys<br /> > and call some code conditionally based on the datatype. Is
thereany way to<br /></div>> determine the datatype of a column from the *backend* PostGreSQL code. is<br /><div
class="im">>the datatype of the column available in the query plan? Any help on this<br /> > would be very much
appreciated.<br/><br /></div>You really need to be more specific about where you need this information.<br /> The
"sortingcode" certainly knows what datatypes it's working with ---<br /> for example, in tuplesort.c there's a
TupleDescfor the tuples passing<br /> through the sort, and the column types are available from the per-column<br />
atttypidfields of that.  But it's not clear if that's what you're talking<br /> about.<br /><br />                    
   regards, tom lane<br /></blockquote></div><br /></div>