Re: [SQL] finding a maximum or minimum sum

2001-06-11 Thread Michael Richards
Prfect! This is exactly what I needed. Didn't know postgres supported subselects like that. Thanks. -Michael > select min(amtsum), max(amtsum), avg(amtsum) > from (select sum(amount) as amtsum from payments group by userid) > ss; > > In prior versions you'd need to do the initial select int

Re: [SQL] finding a maximum or minimum sum

2001-06-11 Thread Tom Lane
"Michael Richards" <[EMAIL PROTECTED]> writes: > I run a select sum(amount) from payments group by userid > I need to modify this query so it returns the minimum, maximum and > average sums. Is there any way I can do this? You need two levels of grouping/aggregating to make that happen. In 7.1 y

[SQL] finding a maximum or minimum sum

2001-06-11 Thread Michael Richards
I have a table that looks like so: userid | amount --- 1 | $500 2 | $400 2 | $-100 2 | $10 3 | $10 3 | $10 I run a select sum(amount) from payments group by userid userid | sum -- 1| $500 2| $310 3| $20 I need to mo

[SQL] problem with Pl/Pgsql function

2001-06-11 Thread Matteo Centenaro
Hi I have a problem with this function: Declare rec_struttura record; rec_camp record; prov int; estra_capo int; id_lista int; estra_non int; rand int8; count int; count_estra int; count_id int; rand_doub flo

[SQL] Table design issue....

2001-06-11 Thread pierre
Hi all, I've got a situation where I need to be able to query for the same sort of data across multiple tables. Let me give some example tables then explain. create table t1 ( t_attr1 text[], t_attr2 text[] ); create table a1 ( a_attr1 text[], a_attr2 text[] ); create table c1 ( c_at

Re: [SQL] Memory exhausted

2001-06-11 Thread Tom Lane
David Richter <[EMAIL PROTECTED]> writes: > I used a self written funtion in plpgsql with a database of 2 Gigabyte > size. My server has 384 Megabytes of RAM. > So I got this error by calling the following function: > psql:restructure.sql:139: FATAL 1: Memory exhausted in AllocSetAlloc() Try

[SQL] Re: seleting all dates between two dates

2001-06-11 Thread Hans-Jürgen Schönig
Jeff Barrett schrieb: > I am interested in a query where I can select all dates between two dates. I > figure I can build a table of all valid dates with a resonable range and > then select from that table, but I would like to use the power of sql to get > the work done without building a date ta

[SQL] Re: select distinct too slow

2001-06-11 Thread Hans-Jürgen Schönig
Did you vacuum analyse your table after creating the index? A solution for your problem would be to turn sequential scans ofd before querying the table. This should work somehow like that: myjava=# SET enable_seqscan TO 'off'; SET VARIABLE myjava=# show enable_seqscan; NOTICE: enable_seqscan is

[SQL] Memory exhausted

2001-06-11 Thread David Richter
Hello! I used a self written funtion in plpgsql with a database of 2 Gigabyte size. My server has 384 Megabytes of RAM. So I got this error by calling the following function: psql:restructure.sql:139: FATAL 1: Memory exhausted in AllocSetAlloc() pqReadData() -- backend closed the channel unex