Re: [SQL] obtaining the query string inside a trigger

2008-01-16 Thread Richard Huxton
Gerardo Herzig wrote: Hi all. Im working on a "on each statement" update trigger, so NEW and OLD are NULL. Suppose a simple query like 'update mytable set id=id+500 where id < 50'...There is a way to obtaining the 'set id=..' and the where clause in some way? Afraid not. It might be possible

Re: [SQL] Update PK Violation

2008-01-16 Thread Fernando Hevia
> Franklin Haut wrote: > > Hi all, > > i have a problem with one update sentence sql. > > example to produce: > > create table temp (num integer primary key, name varchar(20)); > > insert into temp values (1, 'THE'); > insert into temp values (2, 'BOOK'); > insert into temp values (3, 'IS');

Re: [SQL] Update PK Violation

2008-01-16 Thread Achilleas Mantzios
Στις Tuesday 15 January 2008 23:03:49 ο/η Franklin Haut έγραψε: > Hi all, > > i have a problem with one update sentence sql. > A simple way i use: foodb=# update temp set num = num*1000 where num >= 5; foodb=# insert into temp values (5, 'NOT'); foodb=# update temp set num = 1 + num/1000 wher

Re: [SQL] SQL dealing with subquery

2008-01-16 Thread Bryan Emrys
Thanks. It throws off a few extra countries where there is only one treaty, but those are few enough that I can handle them manually. I thought the solution was also going to give me insight into how to select just the lowest rate from each couple, (i.e. for each payor, who is the lowest rate

Re: [SQL] Update PK Violation

2008-01-16 Thread Scott Marlowe
On Jan 16, 2008 8:30 AM, Achilleas Mantzios <[EMAIL PROTECTED]> wrote: > Στις Tuesday 15 January 2008 23:03:49 ο/η Franklin Haut έγραψε: > > Hi all, > > > > i have a problem with one update sentence sql. > > > > A simple way i use: > > foodb=# update temp set num = num*1000 where num >= 5; > foodb

Re: [SQL] Update PK Violation

2008-01-16 Thread Franklin Haut
Scott Marlowe wrote: On Jan 15, 2008 3:03 PM, Franklin Haut <[EMAIL PROTECTED]> wrote: Hi all, i have a problem with one update sentence sql. example to produce: create table temp (num integer primary key, name varchar(20)); insert into temp values (1, 'THE'); insert into temp

Re: [SQL] SQL dealing with subquery

2008-01-16 Thread Bryan Emrys
Following up my treaty rate thoughts, if I'm trying to get the lowest treaty payee (and rate) from a specific list of payees for every possible payor country, the following seems to work, but is it right? I'm specifically wondering about the group by clauses. (Or if there is a better way.) [table t

[SQL] How to test/read a stored procedure that returns a boolean?

2008-01-16 Thread Kevin Jenkins
I wrote this function but I'm not sure how to test it in PG Admin III Query. CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL'; CREATE TABLE handles ( handleID_pk serial PRIMARY KEY UNIQUE NOT NULL, userID_fk integer UNIQUE NOT NULL, handle

Re: [SQL] How to test/read a stored procedure that returns a boolean?

2008-01-16 Thread Tom Lane
Kevin Jenkins <[EMAIL PROTECTED]> writes: > create or replace function IsUsedHandle(h text) returns boolean as $$ > declare > begin > select COUNT(*) as num_matches from handles where handles.handle = h; > return num_matches > 0; > end; > $$ LANGUAGE plpgsql; I think you've confused AS with INTO.

Re: [SQL] How to test/read a stored procedure that returns a boolean?

2008-01-16 Thread Kevin Jenkins
Thanks Tom! Also, how do I check if a language is already created so I don't load it twice? "ERROR: language "plpgsql" already exists SQL state: 42710" Here is the code fixed. /* CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL'; CREATE T