Thread: trigger or something else?
Hello, I have a table that has to have several fields with different names, but equal content. Sounds stupid, but it is because I have 2 different programs querying the same table for user information and each of them uses differently named fields. Eg. I have fields passwd and password. When passwd field changes, password must automatically change to be the same as passwd. I was wondering whether I need a trigger for that, or could I somehow manage to specify that in the "create table" stmt. If I need to do it via trigger, then I apparently need the plpgsql, right? Could you tell which configure option enables that? --enable- plpgsql? Thanks in advamce for any comments. Emils
On Wed, 28 Jun 2000, Emils Klotins wrote: > Hello, > > I have a table that has to have several fields with different names, > but equal content. Sounds stupid, but it is because I have 2 > different programs querying the same table for user information and > each of them uses differently named fields. Why you not use any VIEW, for example: CREATE TABLE xxx (a text); CREATE VIEW v_xxx AS select a as field1, a as field2 from xxx; test=> INSERT INTO xxx VALUES ('qqqqq'); INSERT 380446 1 test=> SELECT * FROM v_xxx;field1 | field2 --------+--------qqqqq | qqqqq (1 row) Karel
>>>>> "EK" == Emils Klotins <emils@dot.lv> writes: EK> Hello,EK> I have a table that has to have several fields with different names, EK> but equal content. Sounds stupid,but it is because I have 2 EK> different programs querying the same table for user information and EK> each of themuses differently named fields. EK> Eg. I have fields passwd and password.EK> When passwd field changes, password must automatically change EK> to be thesame as passwd. EK> I was wondering whether I need a trigger for that, or could I EK> somehow manage to specify that in the "create table"stmt. EK> If I need to do it via trigger, then I apparently need the plpgsql, right?EK> Could you tell which configure option enablesthat? --enable-EK> plpgsql? EK> Thanks in advamce for any comments. EK> Emils I suppose you can use view for your need. For example: create table a ( l varchar(30), p varchar(30) ); create view b as select l as login, p as password from a; insert into a values ('qq', 'ww'); select * from b; tolik=# select * from b;login | password -------+----------qq | ww (1 rows) Unfortunately this way suits for select only, not for 'insert into b' and 'update b' statement. -- Anatoly K. Lasareff Email: tolik@aaanet.ru
> I suppose you can use view for your need. For example: > ... > Unfortunately this way suits for select only, not for 'insert into b' > and 'update b' statement. > Except that you can use rules to update/insert data into tables when an insert/update is done on the view. See the docs for details on how to do this. > > -- > Anatoly K. Lasareff Email: tolik@aaanet.ru Grant -- > Poorly planned software requires a genius to write it > and a hero to use it. Grant Finnemore BSc(Eng) (mailto:gaf@ucs.co.za) Software Engineer Universal Computer Services Tel (+27)(11)712-1366 PO Box 31266 Braamfontein 2017, South Africa Cell (+27)(82)604-5536 20th Floor, 209 Smit St., Braamfontein Fax (+27)(11)339-3421 Johannesburg, South Africa