Re: Redirect sequence access to different schema

From: Magnus Reftel <magnus(dot)reftel(at)gmail(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Redirect sequence access to different schema
Date: 2010-07-26 07:49:21
Message-ID: 9E703B28-F7FC-4D4D-835B-6AD253C1E108@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 without having to modify the application or its database schema. The way I'm trying to achieve this is by setting it up to access a different schema than it usually would, and have that schema act as a proxy for the real schema using views and rules 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));' language sql security definer;

Best Regards
Magnus Reftel

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vincenzo Romano 2010-07-26 09:32:17 Converting BYTEA from/to BIGINT
Previous Message Joe Conway 2010-07-25 21:13:17 Re: Redirect sequence access to different schema