Re: OIDs, CTIDs, updateable cursors and friends

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: OIDs, CTIDs, updateable cursors and friends
Дата
Msg-id 87u0xr3mmn.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на OIDs, CTIDs, updateable cursors and friends  (Shachar Shemesh <psql@shemesh.biz>)
Список pgsql-hackers
Shachar Shemesh <psql@shemesh.biz> writes:

> Would adding "OID" to the rows returned by each "Select" call, and then doing
> "update blah where oid=xxx" when I'm requested to update the row sound like a
> reasonable stategy, in lieu of updateable cursors? Can anyone suggest a better
> way?

If you're in control of the database schema and can ensure that all tables
will have OIDs enabled and you can add a unique index on OID on all these
tables then yes. But it's not ideal. If OID wraps around you'll get errors
from unique key violations.

A better strategy is to pull the primary key columns from information_schema
and use those columns. This would be more work but would work on any table
with a primary key.

This won't work for tables without primary keys, but in that case, arguably,
updating records doesn't really make sense anyways.

Something like this, though I'm not really very familiar with the
information_schema. 

db=> SELECT ordinal_position,column_name       FROM information_schema.table_constraints AS a       JOIN
information_schema.key_column_usageAS b USING (constraint_schema,constraint_name)      WHERE a.constraint_type =
'PRIMARYKEY'        AND a.table_schema = 'public'        AND a.table_name = 'country'      ORDER BY
ordinal_position;ordinal_position| column_name  
 
------------------+--------------               1 | country_code
(1 row)


-- 
greg



В списке pgsql-hackers по дате отправления:

Предыдущее
От: mike g
Дата:
Сообщение: upper() / lower() regression test case needed?
Следующее
От: Christopher Kings-Lynne
Дата:
Сообщение: Re: upper() / lower() regression test case needed?