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 — フィールド番号に対応する型名を返す
説明
string pg_field_type
( resource $result
, int $field_number
)
pg_field_type() は、指定した PostgreSQL の result リソースにおいて、指定した field_number の型名を保持する文字列を 返します。
注意: フィールドが(基本型ではなく)PostgreSQL ドメインを使用している場合は、 ドメインそのものの名前ではなくドメインの元となっている型の名前を返します。
注意: この関数は、以前は pg_fieldtype() と呼ばれていました。
パラメータ
- result
-
pg_query(), pg_query_params() あるいは pg_execute() から返される PostgreSQL の クエリ結果リソース。
- field_number
-
フィールド番号。0 から始まります。
返り値
フィールド型の名前を文字列で返します。エラー時には FALSE を返します。
例
例1 フィールドの情報を取得する
<?php
$dbconn = pg_connect("dbname=publisher") or die("Could not connect");
// 'title' は varchar 型と仮定する
$res = pg_query($dbconn, "select title from authors where author = 'Orwell'");
echo "Title field type: ", pg_field_type($res, 0);
?>
上の例の出力は以下となります。
Title field type: varchar
pg_field_type
marxarelli
03-Jan-2006 07:34
03-Jan-2006 07:34
andy at a 2 h d dot com
04-May-2003 04:09
04-May-2003 04: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.