实际上,您可以通过发送以下查询来提取 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)