Re: trigger function with arguments from a sql command

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: trigger function with arguments from a sql command
Date: 2005-12-07 15:20:59
Message-ID: 20051207152059.GR13724@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

am 07.12.2005, um 15:09:00 -0000 mailte Luis Silva folgendes:
> hi there, i'm having a big problem. I have this table
>
>
> CREATE TABLE test {
>
> id int8 NOT NULL,
> asname varchar(80) NOT NULL,
> priority int2 NOT NULL,
> serviceid,
> ...
>
> CONSTRAIN PRIMARY KEY (id),
> CONSTRAIN FOREIGN KEY (serviceid) REFERENCES service (id) MATCH FULL
> }
>
> and i need to make a trigger function that accept arguments insert in
> a INSERT INTO. The priority value must be unique for the same
> serviceid but it can be the same for different serviceid. how can i do
> that, pass the arguments of a command? tks in advance

1. you can't pass arguments to a trigger
2. you can create a unique index on (priority,serviceid).

test=# create table foobar (id int not null, prio int not null, serviceid int not null);
CREATE TABLE
test=# create unique index idx_foobar on foobar (prio, serviceid);
CREATE INDEX
test=# insert into foobar values (1,1,1);
INSERT 0 1
test=# insert into foobar values (1,1,2);
INSERT 0 1
test=# insert into foobar values (1,2,2);
INSERT 0 1
test=# insert into foobar values (1,2,2);
ERROR: duplicate key violates unique constraint "idx_foobar"

HTH, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47212, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Luis Silva 2005-12-07 15:43:50 Re: trigger function with arguments from a sql command
Previous Message Luis Silva 2005-12-07 15:09:00 trigger function with arguments from a sql command