Re: [SQL] ORDER records based on parameters in IN clause

2005-06-28 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > when I say > select * from table where id IN (2003,1342,799, 1450) > I would like the records to be ordered as 2003, 1342, 799, 1450. Just say: select * from table where id IN (2003,1342,799, 1450) ORDER BY id; If that doesn't work, you will hav

Re: [SQL] people who buy A, also buy C, D, E

2005-06-28 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 >>> The goal of my query is: given a book, what did other people who >>> bought this book also buy? I plan the list the 5 most popular such >>> books. > > SELECT b.product_id, sum(quantity) as rank FROM ordered_products a, > ordered_products b WHER

Re: [SQL] ENUM like data type

2005-06-28 Thread Nick Johnson
Martín Marqués wrote: I personally think that the ENUM data type is for databases that are not well designed. So, if you see the need for ENUM, that means you need to re-think your data design. You mean like all those instances in the PostgreSQL system catalogs where character(1) has been

Re: [SQL] ENUM like data type

2005-06-28 Thread Scott Marlowe
On Tue, 2005-06-28 at 13:22, Martín Marqués wrote: > El Mar 28 Jun 2005 13:58, PFC escribió: > > > > >> Here is where I get uncertain as to if this is possible. My idea is to > > >> create a pseudo type that triggers the creation of it's lookup tables > > >> the same way the SERIAL type triggers c

Re: [SQL] Unique primary index?

2005-06-28 Thread Scott Marlowe
On Tue, 2005-06-28 at 12:01, PFC wrote: > > > > What are the major differences between Unique, primary index & just > > plain index? > > > > When creating tables I nominate one of these, but not sure what the > > difference is? > index is... an index ! > > UNIQUE is an index which won't allow du

Re: [SQL] ENUM like data type

2005-06-28 Thread Martín Marqués
El Mar 28 Jun 2005 13:58, PFC escribió: > > >> Here is where I get uncertain as to if this is possible. My idea is to > >> create a pseudo type that triggers the creation of it's lookup tables > >> the same way the SERIAL type triggers creation of a sequence and returns > >> an int with the right

Re: [SQL] ENUM like data type

2005-06-28 Thread PFC
Here is where I get uncertain as to if this is possible. My idea is to create a pseudo type that triggers the creation of it's lookup tables the same way the SERIAL type triggers creation of a sequence and returns an int with the right default value. Personnally I use one table which has colu

Re: [SQL] Unique primary index?

2005-06-28 Thread PFC
index is... an index ! UNIQUE is an index which won't allow duplicate values (except for NULLS) PRIMARY KEY is exactly like UNIQUE NOT NULL, with the bonus that the database knows this column is the primary key so you can use stuff like NATURAL JOIN without telling which column you want to

Re: [SQL] Unique primary index?

2005-06-28 Thread Bruno Wolff III
On Thu, Jun 23, 2005 at 05:43:52 -0700, [EMAIL PROTECTED] wrote: > > What are the major differences between Unique, primary index & just > plain index? > > When creating tables I nominate one of these, but not sure what the > difference is? A unique key has an implied constraint that no two no

Re: [SQL] ENUM like data type

2005-06-28 Thread Bruno Wolff III
On Tue, Jun 21, 2005 at 17:20:19 +0200, MRB <[EMAIL PROTECTED]> wrote: > > Here is where I get uncertain as to if this is possible. My idea is to > create a pseudo type that triggers the creation of it's lookup tables > the same way the SERIAL type triggers creation of a sequence and returns

Re: [SQL] cross-table reference

2005-06-28 Thread Bruno Wolff III
On Wed, Jun 22, 2005 at 14:56:08 +0530, Mukesh Ghatiya <[EMAIL PROTECTED]> wrote: > Hi, > > I need to perform a query similar to > > SELECT table1.a.b.x table1.a.c.x from table1; > > > In this case "a" is an attribute in 'table1' and is a foreign key to > other table2 which has 'b', and 'c'

Re: [SQL] ENUM like data type

2005-06-28 Thread Mike Rylander
On 6/21/05, MRB <[EMAIL PROTECTED]> wrote: > Hi All, > > I have something in mind I'm not certain is do-able. > > I'm working with a lot of data from MySQL where the MySQL ENUM type is used. > MySQL's ENUM is basically a wrapper for CHECK. You can use a CHECK constraint like this: CREATE TABL

[SQL] ERROR: "TZ"/"tz" not supported

2005-06-28 Thread Sergey Levchenko
When I execute query, I've got error message. test=> SELECT to_timestamp('00:00:05.601 SAMST Tue Jun 28 2005', 'HH24:MI:SS.MS TZ Dy Mon DD '); ERROR: "TZ"/"tz" not supported How can I convert '00:00:05.601 SAMST Tue Jun 28 2005' (varchar type) to timestamp with time zone? -

Re: [SQL] ENUM like data type

2005-06-28 Thread Kenneth Gonsalves
On Tuesday 21 Jun 2005 8:50 pm, MRB wrote: > I'm working with a lot of data from MySQL where the MySQL ENUM type > is used. just a thought - it took me five years after migrating from mysql to pg to start thinking like an sql programmer. I used to keep trying to write stuff for pg 'like' i used

Re: [SQL] Unique primary index?

2005-06-28 Thread M.D.G. Lange
I would say that you should learn a bit about relational databases before you start working with them ;-) All unique fields (or combinations of fields that -combined- are unique) can serve as a primary key. In relational databases we call them 'candidate key'. if you have more than one candid

Re: [SQL] ORDER records based on parameters in IN clause

2005-06-28 Thread Michael Fuhr
On Mon, Jun 27, 2005 at 09:15:15AM -0700, Riya Verghese wrote: > > I have a stmt where the outer-query is limited by the results of the > inner query. I would like the outer query to return records in the same > order as the values provided in the IN clause (returned form the inner > query). If y