Re: Redirect sequence access to different schema

Поиск
Список
Период
Сортировка
От Magnus Reftel
Тема Re: Redirect sequence access to different schema
Дата
Msg-id 9E703B28-F7FC-4D4D-835B-6AD253C1E108@gmail.com
обсуждение исходный текст
Ответ на Re: Redirect sequence access to different schema  (Joe Conway <mail@joeconway.com>)
Список pgsql-general
On Jul 25, 2010, at 23:13 , Joe Conway wrote:
> On 07/25/2010 12:01 PM, Magnus Reftel wrote:
>> create view myseq as select * from other_schema.foo_id_seq;
>>
>> but when I run "select nextval('myseq');" I get an error saying that
>> myseq "is not a sequence". What other options are there?
>
> It isn't clear (to me, at least) what you are trying to accomplish, but
> does this do what you want?

Thanks for the reply! Sorry for not being clear. What I'm after is being able to have some code run on the database
withouthaving to modify the application or its database schema. The way I'm trying to achieve this is by setting it up
toaccess a different schema than it usually would, and have that schema act as a proxy for the real schema using views
andrules that perform the alterations I want. It works fine for tables, but I had trouble with getting ti work with
sequences.

One solution I came up with is to not try to emulate the sequence, but the functions accessing the sequence, as in:

alter function currval(regclass) rename to real_currval;
create function inject.currval(unknown) returns bigint as 'select real_currval(''actual.'' || CAST($1 as text));'
languagesql security definer; 

Best Regards
Magnus Reftel

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

Предыдущее
От: Joe Conway
Дата:
Сообщение: Re: Redirect sequence access to different schema
Следующее
От: Vincenzo Romano
Дата:
Сообщение: Converting BYTEA from/to BIGINT