事实上,您可以通过发送以下查询来提取 varchar 字段的大小:
"select a.atttypmod,a.attrelid from pg_attribute as a, pg_class as c where c.relname='$table' AND a.attrelid=c.oid AND a.attname='$field'"
这是一个简单的执行此操作的函数:
function get_field_size($table, $field, $link) {
$result = pg_query($link, "select a.atttypmod,a.attrelid from pg_attribute as a, pg_class as c where c.relname='$table' AND a.attrelid=c.oid AND a.attname='$field'");
$data = pg_fetch_object($result);
return ($data->atttypmod - 4);
}
返回值是给定字段(也包括 varchar)的大小。