Re: [SQL] Meta integrity

2001-07-26 Thread Tom Lane
Renato De Giovanni <[EMAIL PROTECTED]> writes: >FOREIGN KEY (object_id, 'X') REFERENCES object (id, class_id) Why not just store the class_id in the secondary table (if you're concerned about space, consider using an int4 to represent class_id). Then you can do a direct two-column foreign

Re: [SQL] Re: Restriction by grouping problem.

2001-07-26 Thread Philip Warner
A way to do this is: Select GETFILE From (Select Min(DATETIME),SID From LOGS Group by SID) as MDT, LOGS L Where L.SID = MDT.SID And L.DATETIME = MDT.DATETIME But this fails if there are more than one row for a given SID/DATETIME pair (doe you have a unique

[SQL] Re: Restriction by grouping problem.

2001-07-26 Thread Jeff Barrett
Yeah I have been having a bit of a problem expressing myself in terms of this query, sorry about that. What I need is: SELECT getfile FROM logs (and a restriction that results in finding the rows with the lowest datetime for each unique sid) To define this table a bit more: Logs table has a pr

Re: [SQL] Restriction by grouping problem.

2001-07-26 Thread Josh Berkus
Jeff, > The query I have now: > > SELECT min(datettime), sid FROM logs GROUP by sid; > > This returns the first instance of an sid in the logs table, there > can be > many rows in the table for each sid. The problem I have is that I do > not > need the SID I just need to group the min(d

[SQL] Restriction by grouping problem.

2001-07-26 Thread Jeff Barrett
The query I have now: SELECT min(datettime), sid FROM logs GROUP by sid; This returns the first instance of an sid in the logs table, there can be many rows in the table for each sid. The problem I have is that I do not need the SID I just need to group the min(datetime) by it. I need to return

Re: [SQL] performance issue with distance function

2001-07-26 Thread Jeff Hoffmann
Ryan Littrell wrote: > > I am trying to execute the following command: > > SELECT R.*, distance(L1.lat, L1.lon, L2.lat, L2.lon) AS Distance > FROM Restaurants R, Locations L1, Locations L2, FoodTypeRestaurantIDX FTR > WHERE R.Zipcode=L1.Zipcode AND L2.Zipcode = '93705' AND R.Delivery=true AND >

[SQL] performance issue with distance function

2001-07-26 Thread Ryan Littrell
I am trying to execute the following command: SELECT R.*, distance(L1.lat, L1.lon, L2.lat, L2.lon) AS Distance FROM Restaurants R, Locations L1, Locations L2, FoodTypeRestaurantIDX FTR WHERE R.Zipcode=L1.Zipcode AND L2.Zipcode = '93705' AND R.Delivery=true AND R.RestaurantID=FTR.RestaurantID AND

[SQL] Need help in how to....

2001-07-26 Thread Edipo Elder Fernandes de Melo
Hi, I doing a log to my DB. For this, I writing a trigger that inserts in a log table the user, date, table changed and values changed. I was trying to do a generic procedure and use it on all tables, like this: create function sp_log() returns opaque as ' declare