src/DB/Connecter/PgSQLConnecter.php
function getMetaData($table, $fields_map = true)
    {
        $sql = "select a.column_name, a.is_nullable, a.column_default, p.contype from (
                    select i.column_name, i.is_nullable, i.column_default, i.ordinal_position, c.oid
                    from information_schema.columns i left join pg_class c on c.relname=i.table_name
                    where i.table_name='{$table}'
                ) a left join pg_constraint p on p.conrelid=a.oid and a.ordinal_position = ANY (p.conkey)";

        try {
            $data = $this->pdo->query($sql);
            if ($fields_map) {
                $result = array();
                $data->fetchAll(PDO::FETCH_FUNC, function ($column_name, $is_null, $column_default, $con_type) use (&$result) {
                    $auto_increment = preg_match("/nextval\((.*)\)/", $column_default);
                    $result[$column_name] = array(
                        'primary' => $con_type == 'p',
                        'auto_increment' => $auto_increment,
                        'default_value' => $auto_increment ? '' : strval($column_default),
                        'not_null' => $is_null == 'NO',
                    );
                });
                return $result;
            } else {
                return $data->fetchAll(PDO::FETCH_ASSOC);
            }
        } catch (Exception $e) {
            return array();
        }
    }
function getMetaData($table, $fields_map = true)
    {
        $sql = "select a.column_name, a.is_nullable, a.column_default, p.contype from (
                    select i.column_name, i.is_nullable, i.column_default, i.ordinal_position, c.oid
                    from information_schema.columns i left join pg_class c on c.relname=i.table_name
                    where i.table_name='{$table}'
                ) a left join pg_constraint p on p.conrelid=a.oid and a.ordinal_position = ANY (p.conkey)";

        try {
            $data = $this->pdo->query($sql);
            if ($fields_map) {
                $result = array();
                $data->fetchAll(PDO::FETCH_FUNC, function ($column_name, $is_null, $column_default, $con_type) use (&$result) {
                    $auto_increment = preg_match("/nextval\((.*)\)/", $column_default);
                    $result[$column_name] = array(
                        'primary' => $con_type == 'p',
                        'auto_increment' => $auto_increment,
                        'default_value' => $auto_increment ? '' : strval($column_default),
                        'not_null' => $is_null == 'NO',
                    );
                });
                return $result;
            } else {
                return $data->fetchAll(PDO::FETCH_ASSOC);
            }
        } catch (Exception $e) {
            return array();
        }
    }
获取表的字段信息

@param string $table
@param bool $fields_map
@return array