Re: [SQL] Is there a faster way to do this?

2004-06-15 Thread Jean-Luc Lachance
One way to do it would be to: Not put the percentile in the sales table; Create an percentile table with a foreign key to the sales table primary key and percentile int4: CREATE TABLE percentiles( fkey PRIMARY KEY REFERENCES sales( ), percentile INT4 ); Create a sequence for that ancillary table

Re: [SQL] Is there a faster way to do this?

2004-06-15 Thread Richard Huxton
Patrick Hatcher wrote: Scenario: Each day I update a column in a table with an internal percentile value. To arrive at this value, I'll get a count of records with sales > 0 and then divide this count by the total number of tile groups I want. So for example: Total records w/sales > 0 = 730,000

Re: [SQL] Is there a faster way to do this?

2004-06-15 Thread Edmund Bacon
Perhaps something along the lines of CREATE TEMP SEQUENCE pctile_seq; SELECT ... , ((nextval('pctile_seq')/(rec_per_group+1) +1) FROM (SELECT ... WHERE sales > 0 ORDER BY SALES) sales; DROP TEMP SEQUENCE pctile_seq; This doesn't add in the 'sales = 0 are in percentile 0, but that shouldn't be too

[SQL] Is there a faster way to do this?

2004-06-15 Thread Patrick Hatcher
pg: 7.4.2 RedHat 7.2 Can I get some advice on a possible faster way of doing this: Scenario: Each day I update a column in a table with an internal percentile value. To arrive at this value, I'll get a count of records with sales > 0 and then divide this count by the total number of tile g

Re: [SQL] Prepare Statement

2004-06-15 Thread Jie Liang
Tom, Does java.sql.PreparedStatement do the same thing as SQL command prepare/execute ?? Which one should be used while I am using jdbc talking to postgresql? If using both, do them help the performance? Thanks. Jie Liang -Original Message- From: Jie Liang Sent: Monday, June 14, 200

Re: [SQL] Last insert id

2004-06-15 Thread Rod Taylor
On Tue, 2004-06-15 at 03:05, Andrei Bintintan wrote: > "Is it safe to use "select max(table1_id) from table1" after the insert?" > > Yes it is safe, but ONLY if you use it inside a transaction.(BEGIN/COMMIT). No, this is not safe outside of the serializable isolation. rbt=# begin; BEGIN rbt=# se

Re: [SQL] Last insert id

2004-06-15 Thread Andrei Bintintan
"Is it safe to use "select max(table1_id) from table1" after the insert?" Yes it is safe, but ONLY if you use it inside a transaction.(BEGIN/COMMIT). BR. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of mixo Sent: Wednesday, June 09, 2004 9:24 AM To: [EM