PQfnumber and duplicate column names.... - Mailing list pgsql-novice

From Ralf Hasemann
Subject PQfnumber and duplicate column names....
Date
Msg-id F1570351-E0E3-11D8-9500-000393D76D50@mac.com
Whole thread Raw
Responses Re: PQfnumber and duplicate column names....  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Hi everybody,

at the moemnt I am writing a little app that uses the libpq client
library.

The function PQfnumber returns the column number associated with a
given column name.

Here is the spec of the function:

<snip------------------>
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:

PQfnumber(res, "FOO") 0
PQfnumber(res, "foo") 0
PQfnumber(res, "BAR") -1
PQfnumber(res, "\"BAR\"") 1
<snap------------------->

What happens if the statement looks like:

select 1 as FOO, 2 as FOO;  (the database has no probs with that)

What result will PQfnumber return ????

PQfnumber(res, "FOO") 0 or 1 ???

Thx for all help!

Ralf Hasemann


pgsql-novice by date:

Previous
From: Betsy Barker
Date:
Subject: Re: Problem assigning return value from function to a
Next
From: Eduardo Vázquez Rodríguez
Date:
Subject: UNIX timestamps