私はpostgresqlテーブルの列を扱っています。SQL や pl/pgSQL では簡単ですが、PL/C で列を処理する方法 (例: 列名を取得する、テーブルの列数を取得する、テーブルに XXX という名前の列が存在するかどうかを確認する) は?
1 に答える
1
次のような意味です。
PQnfields
Returns the number of columns (fields) in each row of the query result.
int PQnfields(const PGresult *res);
PQfname
Returns the column name associated with the given column number. Column numbers start at 0. The caller should not free the result directly. It will be freed when the associated PGresult handle is passed to PQclear.
char *PQfname(const PGresult *res,
int column_number);
NULL is returned if the column number is out of range.
PQfnumber
Returns the column number associated with the given column name.
int PQfnumber(const PGresult *res,
const char *column_name);
-1 is returned if the given name does not match any column.
The given name is treated like an identifier in an SQL command, that is, it is downcased unless double-quoted. For example, given a query result generated from the SQL command
select 1 as FOO, 2 as "BAR";
we would have the results:
PQfname(res, 0) foo
PQfname(res, 1) BAR
PQfnumber(res, "FOO") 0
PQfnumber(res, "foo") 0
PQfnumber(res, "BAR") -1
PQfnumber(res, "\"BAR\"") 1
どのような問題がありますか? 呼び出しは非常に簡単です。
于 2012-06-11T04:42:28.887 に答える