Re: [SQL] "large" IN/NOT IN subqueries result in query returning

2005-12-27 Thread John McCawley
At a glance I would guess that NULL values in one or both of your tables is the culprit. NULL values always return false. Example: A quick test on my database: select count(*) FROM tbl_employee; count --- 2689 select count(*) FROM tbl_employee WHERE username IS NULL; count --- 3

Re: [SQL] DB design and foreign keys

2005-12-13 Thread John McCawley
Table orders defines the column order_code as a serial, which simple makes a trigger which gives a new value to the column on insert. Note that there is NO guarantee that ths column will be unique. You can manually update the value to whatever you want. If you wish this column to be unique,

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

[SQL] Performance of a view

2005-11-16 Thread John McCawley
Hello all, I have a fairly complex query whose performance problem I have isolated to a fairly small subset. The pertinent parts of the table structure are as follows: //- tbl_claim claim_id integer SERIAL PRIMARY KEY; claimnum varchar(32); //---