Re: [SQL] Triggers

2005-11-22 Thread Achilleus Mantzios
O Neil Saunders έγραψε στις Nov 22, 2005 : > And change AFER INSERT to BEFORE INSERT 1) it doesnt make any difference since we are updating a different table than the trigger's one 2) Your email text comes really garbled > -- -Achilleus ---(end of broadcast)

Re: [SQL] argument type problem with plpgsql function

2005-11-22 Thread Luca Pireddu
On November 22, 2005 20:24, Tom Lane wrote: > Luca Pireddu <[EMAIL PROTECTED]> writes: > > I just tried it at home on a postgresql 8.0.3 server (debian package) and > > it worked the way it's supposed to. Puzzling... > > Maybe you have more than one blast_evalue() function with different > argumen

Re: [SQL] argument type problem with plpgsql function

2005-11-22 Thread Tom Lane
Luca Pireddu <[EMAIL PROTECTED]> writes: > I just tried it at home on a postgresql 8.0.3 server (debian package) and it > worked the way it's supposed to. Puzzling... Maybe you have more than one blast_evalue() function with different argument types? regards, tom lane -

Re: [SQL] argument type problem with plpgsql function

2005-11-22 Thread Luca Pireddu
On November 22, 2005 17:13, Stephan Szabo wrote: > On Tue, 22 Nov 2005, Luca Pireddu wrote: > [snip] > > I got the same answer (the second) for both calls from my 8.0 and 8.1 > setups, what version were you trying on? > I forgot to mention that. I'm using version 8.0.4, built from source. I just

Re: [SQL] argument type problem with plpgsql function

2005-11-22 Thread Stephan Szabo
On Tue, 22 Nov 2005, Luca Pireddu wrote: > I wrote a little function that has to work with big numbers > > CREATE OR REPLACE FUNCTION blast_evalue(seq_len bigint, db_size bigint, > bit_score double precision) > RETURNS double precision AS $$ > BEGIN > RETURN 2^(bit_score) * db_size * seq_len;

[SQL] argument type problem with plpgsql function

2005-11-22 Thread Luca Pireddu
I wrote a little function that has to work with big numbers CREATE OR REPLACE FUNCTION blast_evalue(seq_len bigint, db_size bigint, bit_score double precision) RETURNS double precision AS $$ BEGIN RETURN 2^(bit_score) * db_size * seq_len; END; $$ LANGUAGE 'plpgsql' IMMUTABLE RETURNS NULL ON N

Re: [SQL] unplanned sub-select error?

2005-11-22 Thread Tom Lane
Kyle Bateman <[EMAIL PROTECTED]> writes: > Sorry, you're right. I have now confirmed that this only happens when > updating via a view/rule (as you suspected). Attached is a minimalist > sql file that demonstrates the same error message from a blank > database. I'm using 8.1.0. I'm pretty su

Re: [SQL] unplanned sub-select error?

2005-11-22 Thread Kyle Bateman
Tom Lane wrote: Kyle Bateman <[EMAIL PROTECTED]> writes: I have a query: insert into mtr_reg_v_wt (ropnum, inum, pnum, rquant, value, status, ddate, fr_proj, to_proj) values (28985,1,1014,1,(select cost from prd_part where pnum = 1014),'work','2005-Nov-15',50,75); That used to w

Re: [SQL] can UNIQUEness of TEXT datatype really be guaranteed?

2005-11-22 Thread Tom Lane
<[EMAIL PROTECTED]> writes: > So I can't help but wonder, can Postgres really guarantee a TEXT field to be > UNIQUE... or is declaring a TEXT field UNIQUE something an uninformed, novice > user would do?... or is it something indicative of the strength and/or > weeknesses that separate the funct

Re: [SQL] can UNIQUEness of TEXT datatype really be guaranteed?

2005-11-22 Thread Jaime Casanova
On 11/22/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am in the process re-implementing some pgsql table declarations into a > MySQL database. I have this one line where I say > ... > fieldname TEXT UNIQUE, > ... > in my pgsql table because I want to ensure that no one enters the same thin

[SQL] can UNIQUEness of TEXT datatype really be guaranteed?

2005-11-22 Thread fmiddleton
I am in the process re-implementing some pgsql table declarations into a MySQL database. I have this one line where I say ... fieldname TEXT UNIQUE, ... in my pgsql table because I want to ensure that no one enters the same thing in this field and I didn't choose VARCHAR type because I have no id

Re: [SQL] Triggers

2005-11-22 Thread Leif B. Kristensen
On Tuesday 22 November 2005 18:07, Achilleus Mantzios wrote: >O Leif B. Kristensen ?? Nov 22, 2005 : >> What am I missing? > >apparently some forgotten process_last_edited() function. Yes -- an earlier attempt at the same thing ... I finally managed to create my first trigger: CREATE O

Re: [SQL] deferrable on unique

2005-11-22 Thread John McCawley
It's a low-tech solution but you could: begin update t1 set seq=-1 where id=5 update t1 set seq=5 where id=4 update t1 set seq=4 where id=-1 end This is assuming that you don't naturally have -1 as a valid value of that column. chester c young wrote: table t1: id integer primary key,

Re: [SQL] Triggers

2005-11-22 Thread Neil Saunders
And change AFER INSERT to BEFORE INSERT On 11/22/05, Achilleus Mantzios <[EMAIL PROTECTED]> wrote: > O Leif B. Kristensen έγραψε στις Nov 22, 2005 : > > > On Tuesday 22 November 2005 17:25, Achilleus Mantzios wrote: > > >O Leif B. Kristensen έγραψε στις Nov 22, 2005 : > > >> I'm trying to understa

[SQL] deferrable on unique

2005-11-22 Thread chester c young
table t1: id integer primary key, seq integer not null unique the seq is for ordering the rows as the user likes. however, if the rows are moved around, eg begin update t1 set seq=4 where id=5 update t1 set seq=5 where id=4 end will bomb because the first update has two rows of seq=4

Re: [SQL] Triggers

2005-11-22 Thread Neil Saunders
Try: create or replace function update_last_edit() returns trigger as $$ begin new.last_edit=now(); return new; end; $$ language plpgsql; On 11/22/05, Leif B. Kristensen <[EMAIL PROTECTED]> wrote: > On Tuesday 22 November 2005 17:25, Achilleus Mantzios wrote: > >O Leif B. Kristensen έγραψε στις N

Re: [SQL] Triggers

2005-11-22 Thread Achilleus Mantzios
O Leif B. Kristensen έγραψε στις Nov 22, 2005 : > On Tuesday 22 November 2005 17:25, Achilleus Mantzios wrote: > >O Leif B. Kristensen έγραψε στις Nov 22, 2005 : > >> I'm trying to understand triggers. I have read the documentation in > >> the manual as well as the few pages in the Douglas book ab

Re: [SQL] Triggers

2005-11-22 Thread Leif B. Kristensen
On Tuesday 22 November 2005 17:25, Achilleus Mantzios wrote: >O Leif B. Kristensen έγραψε στις Nov 22, 2005 : >> I'm trying to understand triggers. I have read the documentation in >> the manual as well as the few pages in the Douglas book about the >> subject, but I don't see how to implement a tr

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread John McCawley
However, if customers or suppliers can have multiple accounts, you are going to need an intermediate table, as suggested by Neil. Scratch that. If accounts can have multiple owners you'll need an intermediate table. ---(end of broadcast)---

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread Rod Taylor
On Tue, 2005-11-22 at 16:24 +0100, Joost Kraaijeveld wrote: > Hi, > > Is there a way to create a foreign key to 2 tables: e.g. a bankaccount > table that has a column "owner", that must point to a record in either > the customer or the supplier table? No. What you need is an owner table that cust

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread John McCawley
I've never seen anything like that. I'm sure it's conceivable that you could write a weird trigger for it, but you have to consider maintainability, and what your queries are going to look like. I haven't seen your datamodel, but it would seem that you could accomplish what you're looking for

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread Achilleus Mantzios
O Joost Kraaijeveld έγραψε στις Nov 22, 2005 : > Hi, > > Is there a way to create a foreign key to 2 tables: e.g. a bankaccount > table that has a column "owner", that must point to a record in either > the customer or the supplier table? While there are techniques to accomplish this, i see a p

Re: [SQL] Foreign key to 2 tables problem

2005-11-22 Thread Neil Saunders
As far as I'm aware, not without using an intermediatary table (id, cust_id, supplier_id) . Otherwise, how would you know which table the foreign key was referencing? That said, an intermediatary table isn't a very clean solution; What problem are you trying to solve, exactly? Kind Regards, Neil

Re: [SQL] Triggers

2005-11-22 Thread Achilleus Mantzios
O Leif B. Kristensen έγραψε στις Nov 22, 2005 : > I'm trying to understand triggers. I have read the documentation in the > manual as well as the few pages in the Douglas book about the subject, > but I don't see how to implement a trigger that simply updates a > 'last_edit' date field in my 'p

[SQL] Foreign key to 2 tables problem

2005-11-22 Thread Joost Kraaijeveld
Hi, Is there a way to create a foreign key to 2 tables: e.g. a bankaccount table that has a column "owner", that must point to a record in either the customer or the supplier table? TIA -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277

[SQL] Triggers

2005-11-22 Thread Leif B. Kristensen
I'm trying to understand triggers. I have read the documentation in the manual as well as the few pages in the Douglas book about the subject, but I don't see how to implement a trigger that simply updates a 'last_edit' date field in my 'persons' table whenever I do an insert or update into my

Re: [SQL] idea for a geographically distributed database: how best to implement?

2005-11-22 Thread Andy Ballingall
David Bath wrote: > There are a couple of philosophical perspectives I've come across in > previous > work with cadastral data that may be useful...[snipped] Thanks, David In this particular application, structures such as postcode sectors, administrative boundaries etc. are not really of much i

Re: [SQL] Please help to wite the constraint.

2005-11-22 Thread Grigory O. Ptashko
> I can't understand why you are doing this big cycle.. but certainly > when constraints can't help you.. you can use triggers to enforce > integrity.. In my system I have to have arbitrary contact info records about my users. I mean not only fixed like names, email and phone but many many other

Re: [SQL] tid_le comparison for tuple id (ctid) values?

2005-11-22 Thread Richard Huxton
Richard Huxton wrote: george young wrote: Well, I don't have any need for it to correlate with the age of the tuple. My use of step.ctid How do you know there is only 1 duplicate? Anyway, if (x,y) are the same but (z) is not then you can compare against max(z) or min(z). Something like:

Re: [SQL] tid_le comparison for tuple id (ctid) values?

2005-11-22 Thread Richard Huxton
george young wrote: Well, I don't have any need for it to correlate with the age of the tuple. My use of step.ctid How do you know there is only 1 duplicate? Anyway, if (x,y) are the same but (z) is not then you can compare against max(z) or min(z). Something like: SELECT t1.x AS update_me_