Hello all
I need to write a function that retrieve the name of at least one
table primary key, if it exists. The only argument passed to the
function is the table name. I have thought something like this:
char *
give_pkey(char * table_char)
TupleDesc tupdesc;
Form_pg_attribute att;
Form_pg_index ind;
int i, c=0, temp=-1;
tupdesc = (TupleDesc) RelationNameGetTupleDesc(tabla_char);
ind = <<something that idicates which table is>>
for (i=0; i<(tupdesc->natts); i++)
{
att = tupdesc->attrs[i];
c = c + 1;
/* Something that can compare each attribute to determine
if it is a primary key ?*/
if ((ind->indisprimary) && (temp=-1))
{
temp = c;
att = tupdesc->attrs[temp];
}
}
return pstrdup(NameStr(att->attname));
}
Sorry, I don't have much experience in c programming, thanks in
advance for any suggestions, regards,
Juan P. Espino
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match