Re: [SQL] ORDER BY and NULLs

2004-10-30 Thread Murphy Pope
>> You should just cross out that whole section. It's just flatly wrong. >> >> I had always assumed it was just people bringing assumptions over from >> Oracle where it is true. Perhaps this book is to blame for some of the >> confusion. Which book is it? >> >> Postgres indexes NULLs. It can use

Re: [SQL] ORDER BY and NULLs

2004-10-30 Thread Murphy Pope
>> I just dug out the PostgreSQL book again because I thought I might've >> garbled it: >> >> Quote: "PostgreSQL will not index NULL values. Because an index will >> never include NULL values, it cannot be used to satisfy the ORDER BY >> clause of a query that returns all rows in a table." > > Yo

Re: [SQL] ORDER BY and NULLs

2004-10-30 Thread Murphy Pope
> You should just cross out that whole section. It's just flatly wrong. > > I had always assumed it was just people bringing assumptions over from > Oracle where it is true. Perhaps this book is to blame for some of the > confusion. Which book is it? > > Postgres indexes NULLs. It can use them fo

Re: [SQL] ORDER BY and NULLs

2004-09-20 Thread T E Schmitz
Hello, Greg Stark wrote: Tom Lane <[EMAIL PROTECTED]> writes: The paragraph continues: "If the SELECT command included the clause WHERE phone NOT NULL, PostgreSQL could use the index to satisfy the ORDER BY clause. An index that covers optional (NOT NULL) columns will not be used to speed table

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> writes: > > The paragraph continues: > > "If the SELECT command included the clause WHERE phone NOT NULL, > > PostgreSQL could use the index to satisfy the ORDER BY clause. > > An index that covers optional (NOT NULL) columns will not be used to > > speed table join

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread T E Schmitz
Hello Tom, Tom Lane wrote: T E Schmitz <[EMAIL PROTECTED]> writes: Greg Stark wrote: Which book is it? PostgreSQL by Korry Douglas + Susan Douglas, ISBN 0-7357-1257-3; Feb 2003 Hmm, I've heard of that book but never seen it. The authors are not participants in the PG community --- AFAICT neither

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Tom Lane
T E Schmitz <[EMAIL PROTECTED]> writes: > Greg Stark wrote: >> Which book is it? > PostgreSQL by Korry Douglas + Susan Douglas, ISBN 0-7357-1257-3; Feb 2003 Hmm, I've heard of that book but never seen it. The authors are not participants in the PG community --- AFAICT neither of them have ever p

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread T E Schmitz
Hello Greg, Greg Stark wrote: T E Schmitz <[EMAIL PROTECTED]> writes: Quote: "PostgreSQL will not index NULL values. Because an index will never include NULL values, it cannot be used to satisfy the ORDER BY clause of a query that returns all rows in a table." You should just cross out that whole

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Tom Lane
T E Schmitz <[EMAIL PROTECTED]> writes: > Tom Lane wrote: >> Whatever you were reading had it pretty badly garbled :-( > I just dug out the PostgreSQL book again because I thought I might've > garbled it: > Quote: "PostgreSQL will not index NULL values. Because an index will > never include NUL

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Greg Stark
T E Schmitz <[EMAIL PROTECTED]> writes: > I just dug out the PostgreSQL book again because I thought I might've garbled > it: > > Quote: "PostgreSQL will not index NULL values. Because an index will never > include NULL values, it cannot be used to satisfy the ORDER BY clause of a > query that r

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread T E Schmitz
Hello Tom, Tom Lane wrote: T E Schmitz <[EMAIL PROTECTED]> writes: I read somewhere that an Index is not going to improve the performance of an ORDER BY if the sort column contains NULLs because NULLs aren't indexed? Whatever you were reading had it pretty badly garbled :-( I just dug out the Pos

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Tom Lane
T E Schmitz <[EMAIL PROTECTED]> writes: > You must've been reading my mind. I was just wondering what to do about > indexing on that particular table. I read somewhere that an Index is not > going to improve the performance of an ORDER BY if the sort column > contains NULLs because NULLs aren't

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread T E Schmitz
Hello Jean-Luc, You must've been reading my mind. I was just wondering what to do about indexing on that particular table. I read somewhere that an Index is not going to improve the performance of an ORDER BY if the sort column contains NULLs because NULLs aren't indexed? For the sake of the ex

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread Jean-Luc Lachance
select ... order by "FROM" is not null, "FROM"; If you have large amount of rows (with or without nulls) it is faster if use a partial index. create index ... on ...("FROM"); create index ... on ...("FROM") where "FROM" is null; JLL [EMAIL PROTECTED] wrote: Use the coalesce() function. (coalesce

Re: [SQL] ORDER BY and NULLs

2004-09-19 Thread terry
Use the coalesce() function. (coalesce returns the first non-null value in its list) Specifically ORDER BY coalesce("TO", 0), "FROM" If you have records in "TO" column whose values is LESS then 0, then you need to replace 0 with something that sorts BEFORE the first most value that your TO res