Re: [SQL] olympics ranking query

2004-08-20 Thread David Garamond
Bruno Wolff III wrote: On Fri, Aug 20, 2004 at 23:40:08 +0700, David Garamond <[EMAIL PROTECTED]> wrote: Challenge question: is there a simpler way to do query #1 (without any PL, and if possible without sequences too? You could use a subselect to count how many countries had a lower medal ranki

Re: [SQL] olympics ranking query

2004-08-20 Thread Tom Lane
David Garamond <[EMAIL PROTECTED]> writes: > This is not quite the same. The ranks are sequential, but they skip, so > as to match the number of participating countries. Oh, I missed that bit. What you really want here is a "running sum" function, that is SELECT running_sum(numranker) a

Re: [SQL] olympics ranking query

2004-08-20 Thread David Garamond
Tom Lane wrote: Challenge question: is there a simpler way to do query #1 (without any PL, and if possible without sequences too? Can't without sequences AFAIK, but you certainly can do it simpler: select setval('seq1', 0); select nextval('seq1'), * from (select count(*) as numranker, gold, silve

Re: [SQL] olympics ranking query

2004-08-20 Thread Bruno Wolff III
On Fri, Aug 20, 2004 at 23:40:08 +0700, David Garamond <[EMAIL PROTECTED]> wrote: > > Challenge question: is there a simpler way to do query #1 (without any > PL, and if possible without sequences too? You could use a subselect to count how many countries had a lower medal ranking and add 1 to

Re: [SQL] olympics ranking query

2004-08-20 Thread Tom Lane
David Garamond <[EMAIL PROTECTED]> writes: > Challenge question: is there a simpler way to do query #1 (without any > PL, and if possible without sequences too? Can't without sequences AFAIK, but you certainly can do it simpler: select setval('seq1', 0); select nextval('seq1'), * from (select c

[SQL] olympics ranking query

2004-08-20 Thread David Garamond
See http://www.athens2004.com/en/OlympicMedals/medals?noc=MGL . create table countrymedal ( countryid CHAR(3) PRIMARY KEY, gold INT NOT NULL, silver INT NOT NULL, bronze INT NOT NULL); COPY countrymedal (countryid, gold, silver, bronze) FROM stdin; ITA 5 6 3 FRA 5

[SQL] Problems importing data

2004-08-20 Thread Devin Whalen
Hey, I am exporting data from one database and importing into another database. I dump the data from one database like so: pg_dump dbname -R -a -f exportFile.sql I then import the data using: psql import_db -f exportFile.sql 1>>import_sql 2>>import_errorlog However, when I do the import my imp

Re: [SQL] multi column foreign key for implicitly unique columns

2004-08-20 Thread Stephan Szabo
On Fri, 20 Aug 2004, Richard Huxton wrote: > It'd be nice to say something like: > > ALTER TABLE status ADD CONSTRAINT user_status_fk > FOREIGN KEY (status) WHERE relation = 'users' > REFERENCES users(status); > > And the flip-side so you can have: > > ALTER TABLE cheque_details ADD CONSTRAINT chq

Re: [SQL] multi column foreign key for implicitly unique columns

2004-08-20 Thread Richard Huxton
Josh Berkus wrote: I have my own issue that forced me to use triggers. Given: table users ( name login PK status etc. ) table status ( status relation label definition PK status, relation ) the relationship is: users.status =