Re: Adding a pg_get_owned_sequence function?

Поиск
Список
Период
Сортировка
От Dagfinn Ilmari Mannsåker
Тема Re: Adding a pg_get_owned_sequence function?
Дата
Msg-id 87v8cfo32v.fsf@wibble.ilmari.org
обсуждение исходный текст
Ответ на Re: Adding a pg_get_owned_sequence function?  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Adding a pg_get_owned_sequence function?  (Nathan Bossart <nathandbossart@gmail.com>)
Список pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Peter Eisentraut <peter@eisentraut.org> writes:
>> Would it work to just overload pg_get_serial_sequence with regclass 
>> argument types?
>
> Probably not; the parser would have no principled way to resolve
> pg_get_serial_sequence('foo', 'bar') as one or the other.  I'm
> not sure offhand if it would throw error or just choose one, but
> if it just chooses one it'd likely be the text variant.

That works fine, and it prefers the text version:

~=# create function pg_get_serial_sequence(tbl regclass, col name)
    returns regclass strict stable parallel safe
    return pg_get_serial_sequence(tbl::text, col::text)::regclass;
CREATE FUNCTION

~=# select pg_typeof(pg_get_serial_sequence('identest', 'id'));
┌───────────┐
│ pg_typeof │
├───────────┤
│ text      │
└───────────┘
(1 row)

~=# select pg_typeof(pg_get_serial_sequence('identest', 'id'::name));
┌───────────┐
│ pg_typeof │
├───────────┤
│ regclass  │
└───────────┘
(1 row)

> It's possible that we could get away with just summarily changing
> the argument type from text to regclass.  ISTR that we did exactly
> that with nextval() years ago, and didn't get too much push-back.
> But we couldn't do the same for the return type.  Also, this
> approach does nothing for the concern about the name being
> misleading.

Maybe we should go all the way the other way, and call it
pg_get_identity_sequence() and claim that "serial" is a legacy form of
identity columns?

- ilmari



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: remaining sql/json patches
Следующее
От: stepan rutz
Дата:
Сообщение: Re: Detoasting optionally to make Explain-Analyze less misleading