Ruckusing_Adapter_PgSQL_Base::primary_keys PHP Method

primary_keys() public method

get primary keys
public primary_keys ( string $table_name ) : array
$table_name string the table name
return array
    public function primary_keys($table_name)
    {
        $sql = <<<SQL
      SELECT
        pg_attribute.attname,
        format_type(pg_attribute.atttypid, pg_attribute.atttypmod)
      FROM pg_index, pg_class, pg_attribute
      WHERE
        pg_class.oid = '%s'::regclass AND
        indrelid = pg_class.oid AND
        pg_attribute.attrelid = pg_class.oid AND
        pg_attribute.attnum = any(pg_index.indkey)
        AND indisprimary
SQL;
        $sql = sprintf($sql, $table_name);
        $result = $this->select_all($sql);
        $primary_keys = array();
        foreach ($result as $row) {
            $primary_keys[] = array('name' => $row['attname'], 'type' => $row['format_type']);
        }
        return $primary_keys;
    }