dbTalk Databases Forums  

PQfnumber and duplicate column names....

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss PQfnumber and duplicate column names.... in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ralf Hasemann
 
Posts: n/a

Default PQfnumber and duplicate column names.... - 07-28-2004 , 05:17 PM






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


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: PQfnumber and duplicate column names.... - 07-28-2004 , 07:34 PM






Ralf Hasemann <rhasemann (AT) mac (DOT) com> writes:
Quote:
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 ????
When in doubt, look in the source code ...

/*
* PQfnumber: find column number given column name
*
* The column name is parsed as if it were in a SQL statement, including
* case-folding and double-quote processing. But note a possible gotcha:
* downcasing in the frontend might follow different locale rules than
* downcasing in the backend...
*
* Returns -1 if no match. In the present backend it is also possible
* to have multiple matches, in which case the first one is found.
*/


regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.