protected function createTableInfo($table)
{
list($schemaName, $tableName) = $this->getSchemaTableName($table);
// This query is made much more complex by the addition of the 'attisserial' field.
// The subquery to get that field checks to see if there is an internally dependent
// sequence on the field.
$sql = <<<EOD
\t\tSELECT
\t\t\ta.attname,
\t\t\tpg_catalog.format_type(a.atttypid, a.atttypmod) as type,
\t\t\ta.atttypmod,
\t\t\ta.attnotnull, a.atthasdef, adef.adsrc,
\t\t\t(
\t\t\t\tSELECT 1 FROM pg_catalog.pg_depend pd, pg_catalog.pg_class pc
\t\t\t\tWHERE pd.objid=pc.oid
\t\t\t\tAND pd.classid=pc.tableoid
\t\t\t\tAND pd.refclassid=pc.tableoid
\t\t\t\tAND pd.refobjid=a.attrelid
\t\t\t\tAND pd.refobjsubid=a.attnum
\t\t\t\tAND pd.deptype='i'
\t\t\t\tAND pc.relkind='S'
\t\t\t) IS NOT NULL AS attisserial
\t\tFROM
\t\t\tpg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef
\t\t\tON a.attrelid=adef.adrelid
\t\t\tAND a.attnum=adef.adnum
\t\t\tLEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid
\t\tWHERE
\t\t\ta.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=:table
\t\t\t\tAND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE
\t\t\t\tnspname = :schema))
\t\t\tAND a.attnum > 0 AND NOT a.attisdropped
\t\tORDER BY a.attnum
EOD;
$this->getDbConnection()->setActive(true);
$command = $this->getDbConnection()->createCommand($sql);
$command->bindValue(':table', $tableName);
$command->bindValue(':schema', $schemaName);
$tableInfo = $this->createNewTableInfo($schemaName, $tableName);
$index = 0;
foreach ($command->query() as $col) {
$col['index'] = $index++;
$this->processColumn($tableInfo, $col);
}
if ($index === 0) {
throw new TDbException('dbmetadata_invalid_table_view', $table);
}
return $tableInfo;
}