pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
trigger or something else?
4+ messages / 4 participants
[nested] [flat]

* trigger or something else?
@ 2000-06-28 10:29  Emils Klotins <emils@dot.lv>
  0 siblings, 2 replies; 4+ messages in thread

From: Emils Klotins @ 2000-06-28 10:29 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: trigger or something else?
@ 2000-06-28 10:52  Karel Zak <zakkr@zf.jcu.cz>
  parent: Emils Klotins <emils@dot.lv>
  1 sibling, 0 replies; 4+ messages in thread

From: Karel Zak @ 2000-06-28 10:52 UTC (permalink / raw)
  To: Emils Klotins <emils@dot.lv>; +Cc: pgsql-sql


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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: trigger or something else?
@ 2000-06-28 10:57  Anatoly K. Lasareff <tolik@aaanet.ru>
  parent: Emils Klotins <emils@dot.lv>
  1 sibling, 1 reply; 4+ messages in thread

From: tolik@aaanet.ru @ 2000-06-28 10:57 UTC (permalink / raw)
  To: Emils Klotins <emils@dot.lv>; +Cc: pgsql-sql

>>>>> "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 them uses differently named fields.

 EK> Eg. I have fields passwd and password.
 EK> When passwd field changes, password must automatically change 
 EK> to be the same 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 enables that? --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 



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: trigger or something else?
@ 2000-07-03 09:34  Grant Finnemore <gaf@ucs.co.za>
  parent: Anatoly K. Lasareff <tolik@aaanet.ru>
  0 siblings, 0 replies; 4+ messages in thread

From: Grant Finnemore @ 2000-07-03 09:34 UTC (permalink / raw)
  To: Anatoly K. Lasareff <tolik@aaanet.ru>; +Cc: Emils Klotins <emils@dot.lv>; pgsql-sql

> 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






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2000-07-03 09:34 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-06-28 10:29 trigger or something else? Emils Klotins <emils@dot.lv>
2000-06-28 10:52 ` Karel Zak <zakkr@zf.jcu.cz>
2000-06-28 10:57 ` Anatoly K. Lasareff <tolik@aaanet.ru>
2000-07-03 09:34   ` Grant Finnemore <gaf@ucs.co.za>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox