Thread: Types

Types

From
Michael Meskes
Date:
libpq gives back the internal typenumbers of the attributes. How do I know
which number means which type? I need to find out if the type is an array.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!


Re: [HACKERS] Types

From
"Oliver Elphick"
Date:
Michael Meskes wrote: >libpq gives back the internal typenumbers of the attributes. How do I know >which number means
whichtype? I need to find out if the type is an array.
 

If the type is 1007, then:

template1=> select typname from pg_type where oid = 1007;
typname
-------
_int4  
(1 row)

If the typename begins with an underscore, it is an array type.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver              PGP key from public servers; key
ID32B8FAA1                ========================================    "He that giveth unto the poor shall not lack..."
                            Proverbs 28:27 
 




Re: [HACKERS] Types

From
Michael Meskes
Date:
On Sat, Jan 22, 2000 at 10:56:19AM +0000, Oliver Elphick wrote:
> If the type is 1007, then:
> 
> template1=> select typname from pg_type where oid = 1007;
> typname
> -------
> _int4  
> (1 row)
> 
> If the typename begins with an underscore, it is an array type.

Thanks.

Michael

-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!


Re: [HACKERS] Types

From
Tom Lane
Date:
"Oliver Elphick" <olly@lfix.co.uk> writes:
> Michael Meskes wrote:
>> libpq gives back the internal typenumbers of the attributes. How do I know
>> which number means which type? I need to find out if the type is an array.

> If the type is 1007, then:

> template1=> select typname from pg_type where oid = 1007;
> typname
> -------
> _int4  
> (1 row)

Right...

> If the typename begins with an underscore, it is an array type.

If you are going to the trouble of looking in pg_type, then you
shouldn't rely on the convention that array type names begin with
underscores.  What you *should* do is look at the typelem field.
If that's zero, it's not an array; if nonzero, it is an array type
(and typelem gives the OID of the array elements' type).
        regards, tom lane