Returning the name of a primary key
От | Juan Pablo Espino |
---|---|
Тема | Returning the name of a primary key |
Дата | |
Msg-id | 3e7daec1050516112511c165f@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Returning the name of a primary key
Re: Returning the name of a primary key |
Список | pgsql-hackers |
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
В списке pgsql-hackers по дате отправления: