Re: AW: AW: Cast INTEGER to BIT confusion - Mailing list pgsql-general

From GF
Subject Re: AW: AW: Cast INTEGER to BIT confusion
Date
Msg-id CAFePLY0RrbdzPiJVqSSnnPPfavYwGfRx9U_=2BK_uh96ekb28Q@mail.gmail.com
Whole thread Raw
In response to Re: AW: AW: Cast INTEGER to BIT confusion  (Erik Wienhold <ewie@ewie.name>)
Responses Re: AW: AW: Cast INTEGER to BIT confusion  (GF <phabriz@gmail.com>)
List pgsql-general

Erik,
The could be a possible solution, if you could play with search_path...
You could mirror all the original schema onto another one with views that have the original table names.
For all tables that need some special treatment you can then write instead-of triggers, while all other views are updatable.

E.g., let's say they gave you a schema like:
create schema original;
create table original.t(f1 bit);
create table original.u(f2 int);

You can mirror it in this way:
create schema mirror;
create view mirror.t as select f1::int from original.t;
create view mirror.u as select * from original.u;
create function mirror.ins_t() returns trigger as $$ begin insert into original.t(f1) values((new.f1)::bit); return null; end; $$ language plpgsql;
create trigger ins_t instead of insert on mirror.t for each row execute function mirror.ins_t();
-- And something like that for upd and del...

The user that you use to connect must be granted the rights on mirror views and on original tables that need conversion. Its default search_path must be altered to the mirror schema (if you are not already able to do so on the connection string):
create user foo;
alter user foo set search_path to mirror;
grant usage on schema original, mirror to foo;
grant insert, update, delete on original.t, mirror.t, mirror.u to foo;  -- you need original.t but not original.u...

And now you can do:
psql -U foo -c "insert into t values(1)" -c "insert into u values(42)"

Best,
Giovanni


pgsql-general by date:

Previous
From: Rumpi Gravenstein
Date:
Subject: Looking for PostgreSQL Tuning Workshop Presenter
Next
From: GF
Date:
Subject: Re: AW: AW: Cast INTEGER to BIT confusion