Обсуждение: row description, protocol 3

Поиск
Список
Период
Сортировка

row description, protocol 3

От
"Josh Close"
Дата:
I'm getting row description and row data back from Postgres, but I can't figure out how to get the datatype of the row
field.<br/><br />There is a type modifier and an oid of a the field's data type, but I haven't found anywhere those
matchup with Postgres data types. <br /><br />Where can I get the data type from the row description?<br /><br
/>-Josh<br/> 

Re: row description, protocol 3

От
John DeSoi
Дата:
Johsh,

On Feb 28, 2006, at 12:53 AM, Josh Close wrote:

> I'm getting row description and row data back from Postgres, but I  
> can't figure out how to get the datatype of the row field.
>
> There is a type modifier and an oid of a the field's data type, but  
> I haven't found anywhere those match up with Postgres data types.
>
> Where can I get the data type from the row description?

The oid maps to the pg_type table:

select oid, typname from pg_type order by oid;



John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



Re: row description, protocol 3

От
Tom Lane
Дата:
John DeSoi <desoi@pgedit.com> writes:
> On Feb 28, 2006, at 12:53 AM, Josh Close wrote:
>> Where can I get the data type from the row description?

> The oid maps to the pg_type table:
> select oid, typname from pg_type order by oid;

Also, the format_type function might be useful:

regression=# select format_type(1042, 44); format_type  
---------------character(40)
(1 row)

        regards, tom lane


Re: row description, protocol 3

От
"Josh Close"
Дата:
The oid maps to the pg_type table:

select oid, typname from pg_type order by oid;

So, after a select is done, and I get a row description back, I need to do another query to find out what the actual type was?

I'm writing a dataprovider, so I need to map the types back to .NET types. It seems kinda odd that you'd have to do a second query to find out the type.

Re: row description, protocol 3

От
John DeSoi
Дата:
On Feb 28, 2006, at 8:13 PM, Josh Close wrote:

> So, after a select is done, and I get a row description back, I  
> need to do another query to find out what the actual type was?
>
> I'm writing a dataprovider, so I need to map the types back to .NET  
> types. It seems kinda odd that you'd have to do a second query to  
> find out the type.


The majority will correspond to fixed types in PostgreSQL. I just  
used this type list to build a program that parses the data into the  
native type of the application. Or if you just need to know the name  
of the type, build some kind of lookup table in the application. You  
could also do the lookup once and then cache the result.

John



John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL