Re: [SQL] Some insight on the proper SQL would be appreciated

2010-06-08 Thread Aaron Burnett
Thank you so much Oliver. This also worked perfectly. On 6/8/10 1:55 PM, "Oliveiros d'Azevedo Cristina" wrote: > Howdy, Aaron, > > For me this is not an easy question, specially when I don't have your data > here on my PC to test. > > But as a first approach, try this query. It is designed

Re: [SQL] Some insight on the proper SQL would be appreciated

2010-06-08 Thread Aaron Burnett
Mikhail, Thank you very much. This seems to have worked perfectly. On 6/8/10 1:58 PM, "Mikhail V. Puzanov" wrote: > Hi, > > Something very straightforward looks like this, I guess: > > select * from users u > where ( > select count(*) from users u1 > where u1.username = u.username

Re: [SQL] Some insight on the proper SQL would be appreciated

2010-06-08 Thread Mikhail V. Puzanov
Hi, Something very straightforward looks like this, I guess: select * from users u where ( select count(*) from users u1 where u1.username = u.username and u1.signedup> u.signedup )< 5 to get recent results. Or "u1.signedup< u.signedup" for the first ones. But that doesn't work i

Re: [SQL] Some insight on the proper SQL would be appreciated

2010-06-08 Thread Oliveiros d'Azevedo Cristina
Howdy, Aaron, For me this is not an easy question, specially when I don't have your data here on my PC to test. But as a first approach, try this query. It is designed to give you the oldest 5 entries. But, be aware that this is non-tested code. Be prepared for it to not work or even to cont

[SQL] Some insight on the proper SQL would be appreciated

2010-06-08 Thread Aaron Burnett
Greetings, Any help on this would be appreciated. I have a table which is a list of users who entered a contest. They can enter as many times as they want, but only 5 will count. So some users have one entry, some have as many as 15. How could I distill this down further to give me a list that

Re: [SQL] Casts in foreign schemas

2010-06-08 Thread Tom Lane
Ben Morrow writes: > My understanding of things was that PL/pgSQL functions were compiled at > CREATE FUNCTION time, using the SEARCH_PATH currently in effect. Is that > wrong? Yes. They're compiled at first use within a given session. If you want to lock down the search path used by a function

[SQL] Casts in foreign schemas

2010-06-08 Thread Ben Morrow
Is this behaviour expected? (This is with 8.4.3 on FreeBSD.) create schema one; set search_path to one; create type foo as (x integer); create function foo (integer) returns foo language plpgsql as $$ declare y foo; begin