Unix Technical Forum

trigger function with arguments from a sql command

This is a discussion on trigger function with arguments from a sql command within the pgsql Novice forums, part of the PostgreSQL category; --> hi there, i'm having a big problem. I have this table CREATE TABLE test { id int8 NOT NULL, ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:21 PM
Luis Silva
 
Posts: n/a
Default trigger function with arguments from a sql command

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:21 PM
A. Kretschmer
 
Posts: n/a
Default Re: trigger function with arguments from a sql command

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 ===

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 10:21 PM
Luis Silva
 
Posts: n/a
Default Re: trigger function with arguments from a sql command

It works!!!! Tks a lot, your the men!!


----- Original Message -----
From: "A. Kretschmer" <andreas.kretschmer@schollglas.com>
To: <pgsql-novice@postgresql.org>
Sent: Wednesday, December 07, 2005 3:20 PM
Subject: Re: [NOVICE] trigger function with arguments from a sql command


> 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 ===
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org
>


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:11 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com