Because complete documentation is always helpful, here are all the PostgreSQL general purpose types as they are listed in the 8.1 documentation, and each corresponding string returned by pg_field_type().
bigint => int8
bigserial => int8
bit => bit
bit varying => varbit
boolean => bool
box => box
bytea => bytea
character varying => varchar
character => bpchar
cidr => cidr
circle => circle
date => date
double precision => float8
inet => inet
integer => int4
interval => interval
line => line
lseg => lseg
macaddr => macaddr
money => money
numeric => numeric
path => path
point => point
polygon => polygon
real => float4
smallint => int2
serial => int4
text => text
time => time
time with time zone => timetz
timestamp => timestamp
timestamp with time zone => timestamptz
And for the record... (note the 7.4 client lib)
# postmaster --version
postmaster (PostgreSQL) 8.0.4
# ldd libphp4.so
...
libpq.so.3 => /usr/lib/libpq.so.3 (0xb7ac8000)
...
pg_field_type
(PHP 4 >= 4.2.0, PHP 5)
pg_field_type — Zwraca typ wskazanej kolumny
Opis
pg_field_type() zwraca łańcuch zawierający typ podstawowy kolumny wskazanej przez numer_kolumny w wyniku wynik PostgreSQL-a.
Informacja: Jeśli kolumna używa domeny PostgreSQL (zamiast typu podstawowego), jest to nazwa podstawowego typu domeny, który jest zwrócony, zamiast nazwy samej domeny.
Informacja: Ta funkcja dawniej nazywała się pg_fieldtype().
Parametry
- wynik
-
Identyfikator wyniku zapytania do bazy PostgreSQL, zwrócony przez funkcję pg_query(), pg_query_params() lub pg_execute() (między innymi).
- numer_pola
-
Numer pola, zaczynając od zera.
Zwracane wartości
Łańcuch (ang. string) zawierający podstawową nazwę typu pola, lub FALSE w przypadku błędu.
Przykłady
Example #1 Pobieranie informacji o kolumnach
<?php
$polaczenie_do_bazy = pg_connect("dbname=publisher") or die("Nie można się połączyć");
// Załóżmy, że 'tytul' jest typu varchar
$res = pg_query($polaczenie_do_bazy, "select tytul from autorzy where autor = 'Orwell'");
echo "Typ pola tytułu: ", pg_field_type($res, 0);
?>
Powyższy przykład wyświetli:
Typ pola tytułu: varchar
pg_field_type
02-Jan-2006 11:34
03-May-2003 09:09
The types returned are:
bool
int2 (smallint)
int4
int8 (bigint)
numeric
float4 (real / float)
float8 (double)
timestamp
date
time
varchar
bpchar (fixed leng string, 'blank padded char')
inet (ip address)
money
There are some other more esoteric types, e.g. 'circle', but these are the most common.
