[SQL] select vs. select count

2007-03-27 Thread Claus Guttesen
Hi. I'm performing the following query to get all items sold in 2006 which are in category prints or gifts, but not in extra: select order_id from (select o.order_id from orders o join order_lines ol using (order_id) where o.time '2006-01-01T00:00' and o.time '2007-01-01T00:00' and

Re: [SQL] select vs. select count

2007-03-27 Thread Claus Guttesen
Forgot to mention that this is on postgresql 7.4.14 and FreeBSD 6.2. regards Claus Hi. I'm performing the following query to get all items sold in 2006 which are in category prints or gifts, but not in extra: select order_id from (select o.order_id from orders o join order_lines ol using

[SQL] Foreign Unique Constraint

2007-03-27 Thread Jon Horsman
I was wondering if someone could help point me in the right direction w.r.t. foreign unique constraints. I'm working on a legacy database and have a new requirement and am not sure how to do it. I have something like this create table table1 ( id SERIAL PRIMARY KEY extension UNIQUE, other

Re: [SQL] Foreign Unique Constraint

2007-03-27 Thread A. Kretschmer
am Tue, dem 27.03.2007, um 9:21:44 -0400 mailte Jon Horsman folgendes: I was wondering if someone could help point me in the right direction w.r.t. foreign unique constraints. I'm working on a legacy database and have a new requirement and am not sure how to do it. I have something like

Re: [SQL] select vs. select count

2007-03-27 Thread Peter Eisentraut
Claus Guttesen wrote: Why does select and select(count) produce two different results? count(expression) only counts nonnull values. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---(end of broadcast)--- TIP 2: Don't 'kill -9' the

Re: [SQL] Foreign Unique Constraint

2007-03-27 Thread Jon Horsman
create table table1 ( id SERIAL PRIMARY KEY extension UNIQUE, I can't find anything about this syntax in the docs... Oops, i'm missing a comma on that first line, should have been: create table table1 ( id SERIAL PRIMARY KEY, extension UNIQUE, ) I think, you should write a TRIGGER for

Re: [SQL] array_to_string

2007-03-27 Thread Tom Lane
Sabin Coanda [EMAIL PROTECTED] writes: I used the function array_to_string, and I found it ignores NULL values, e.g. array_to_string( 'ARRAY[1,NULL,3]', ',' ) returns '1,3'. Do you have a better idea? regards, tom lane ---(end of

Re: [SQL] array_to_string

2007-03-27 Thread Richard Huxton
Tom Lane wrote: Sabin Coanda [EMAIL PROTECTED] writes: I used the function array_to_string, and I found it ignores NULL values, e.g. array_to_string( 'ARRAY[1,NULL,3]', ',' ) returns '1,3'. Do you have a better idea? If you're being strict it should presumably return NULL for the whole

Re: [SQL] array_to_string

2007-03-27 Thread Tom Lane
Richard Huxton dev@archonet.com writes: Tom Lane wrote: Sabin Coanda [EMAIL PROTECTED] writes: I used the function array_to_string, and I found it ignores NULL values, e.g. array_to_string( 'ARRAY[1,NULL,3]', ',' ) returns '1,3'. Do you have a better idea? If you're being strict it

Re: [SQL] array_to_string

2007-03-27 Thread Richard Huxton
Tom Lane wrote: Richard Huxton dev@archonet.com writes: Tom Lane wrote: Sabin Coanda [EMAIL PROTECTED] writes: I used the function array_to_string, and I found it ignores NULL values, e.g. array_to_string( 'ARRAY[1,NULL,3]', ',' ) returns '1,3'. Do you have a better idea? If you're being

Re: [SQL] Foreign Unique Constraint

2007-03-27 Thread Peter Eisentraut
Jon Horsman wrote: Basically table 1 and table 2 both have the concept of an extension that must be unique but the rest of the info in the tables are different.  I need to ensure that if i add an entry to table 1 with extension 1000 that it will fail if there is already an entry in table2

Re: [SQL] select vs. select count

2007-03-27 Thread Tom Lane
Claus Guttesen [EMAIL PROTECTED] writes: select order_id from (select o.order_id from orders o join order_lines ol using (order_id) where o.time '2006-01-01T00:00' and o.time '2007-01-01T00:00' and (ol.item_id = 10 or ol.item_id = 11 or ol.item_id = 12) group by o.order_id) as prints

Re: [SQL] Foreign Unique Constraint

2007-03-27 Thread chester c young
create table table1 ( id SERIAL PRIMARY KEY extension UNIQUE, other fields ) create table table2 ( id SERIAL PRIMARY KEY extension UNIQUE, different fields ) Basically table 1 and table 2 both have the concept of an extension that must be unique but the rest of the info in the

Re: [SQL] Regular Expressions

2007-03-27 Thread ezequias
Guy, Could you give me a hand ? I have a ZipCode table and my address table I just would like to find out all matches that my zipcode table has where my address table appears like this: Elmo Street, 30 I would like my SQL find out all matches we can find 'Elmo', 'Street'. The commas,

Re: [SQL] Regular Expressions

2007-03-27 Thread Richard Broersma Jr
Could you give me a hand ? I have a ZipCode table and my address table I just would like to find out all matches that my zipcode table has where my address table appears like this: Elmo Street, 30 I would like my SQL find out all matches we can find 'Elmo', 'Street'. select

Re: [SQL] Foreign Unique Constraint

2007-03-27 Thread Phillip Smith
Perhaps this...? It would work, but depending how many rows are in the table, it could become incredibly slow. ALTER TABLE table1 ADD CHECK (extension NOT IN (SELECT extension FROM table2)); And the converse for table2: ALTER TABLE table2 ADD CHECK (extension NOT IN (SELECT extension FROM

Re: [SQL] Foreign Unique Constraint

2007-03-27 Thread Jon Horsman
Perhaps this...? It would work, but depending how many rows are in the table, it could become incredibly slow. The max rows in either table would be about 1000 or so, which isn't too many. There also should be a hole lot of inserting going on. ALTER TABLE table1 ADD CHECK (extension NOT IN