©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
(PHP 4 >= 4.2.0, PHP 5)
pg_field_size — 返回指定字段占用内部存储空间的大小
$result
, int $field_number
) pg_field_size() 返回 PostgreSQL result
中指定字段占用内部存储空间的大小(字节数)。字段编号从 0 开始。字段大小为 -1 表示可变长度字段。如果出错本函数返回 FALSE
。
参考 pg_field_name() 页面中的例子。
Note:
本函数以前的名字为 pg_fieldsize()。
参见 pg_field_prtlen() 和 pg_field_type() 。
[#1] ij at NOSPAM dot irj dot co dot za [2005-06-14 04:21:44]
To view the file structure of a table using a sql query
select pg_class.relname, pg_attribute.attname, pg_type.typname, pg_type.typlen from pg_class, pg_attribute, pg_type where pg_class.relname = 'YOURTABLENAME' and pg_class.oid = pg_attribute.attrelid and pg_type.oid = pg_attribute.atttypid having attnum > 0
[#2] php at tribun dot de [2005-02-23 05:49:50]
function get_create_syntax( $table )
{
$qry = "
SELECT *
FROM $table
LIMIT 1
";
$res = pg_query( $qry );
$row = pg_fetch_assoc( $res );
$create = "CREATE TABLE $table \n(\n";
$item = array();
for( $i = 0; $i < count( $row ); $i++ )
{
$name = pg_field_name( $res, $i );
$type = pg_field_type( $res, $i );
$size = pg_field_size( $res, $i );
$item[$i] = '"'.$name.'" '.$type;
$qry = "
SELECT a.atttypmod AS size,
a.attnotnull AS notnull
FROM pg_attribute AS a,
pg_class AS c
WHERE c.relname = '$table'
AND a.attrelid = c.oid
AND a.attname = '$name'
";
$res2 = pg_query( $qry );
$out = pg_fetch_object( $res2 );
if( $out -> size != -1 )
{
$item[$i] .= '('.( $out -> size - 4 ).')';
}
if( $out -> notnull == 't' )
$item[$i] .= ' NOT';
$item[$i] .= ' NULL';
}
$create .= implode( ",\n", $item ) ."\n);";
return $create;
}
[#3] alex at linuxNOSPAM dot org dot pe [2002-07-02 21:44:56]
How i can extract the struct of a Postgresql Table?
I want to do a dynamic php code, that see the pg table, and print name, type and size of fields