略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pg_field_size

2024-11-14

pg_field_size

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_field_size 返回指定字段占用内部存储空间的大小

说明

pg_field_size(resource $result, int $field_number): int

pg_field_size() 返回 PostgreSQL result 中指定字段占用内部存储空间的大小(字节数)。字段编号从 0 开始。字段大小为 -1 表示可变长度字段。如果出错本函数返回 false

参考 pg_field_name() 页面中的例子。

注意:

本函数以前的名字为 pg_fieldsize()

参见 pg_field_prtlen()pg_field_type()

add a noteadd a note

User Contributed Notes 3 notes

up
0
ij at NOSPAM dot irj dot co dot za
17 years ago
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
up
0
php at tribun dot de
17 years ago
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;
}
up
-3
alex at linuxNOSPAM dot org dot pe
19 years ago
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

官方地址:https://www.php.net/manual/en/function.pg-field-size.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3