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  (Alvaro Herrera <alvherre@surnet.cl>)
Re: Returning the name of a primary key  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: alternate regression dbs?
Следующее
От: Hannu Krosing
Дата:
Сообщение: Re: bitmap scans, btree scans, and tid order