From: "Raif S. Naffah" Date: 2004-11-27T04:48:08+09:00 Subject: Re: ActiveRecord (1.1) question -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 On Sat, 27 Nov 2004 12:35 am, Han Holl wrote: > On Friday 26 November 2004 11:24, David Heinemeier Hansson wrote: > > > at = Attack.find_by_sql(\ > > > "SELECT MIN(occured_on) " +\ > > > "FROM attacks " +\ > > > "WHERE occured_on BETWEEN '#{start_date_str}' AND > > > '#{end_date_str}'")[0].min > > > > Try using Attact.connection.select_one("SELECT MIN(occured_on)...") > > > > That should return the value without needing to do [0].min. I'm > > actually not quite sure why it works on your machine. I would have > > thought you needed to do "MIN(occured_on) as min" to get the effect > > you're looking for. i'll try that and see if it solves the mysql case. > Postgresql calls the result fo the min function min by default: > > palga=> select min(datont) from main; > min > ------------ > 1990-01-01 > (1 row) indeed; otherwise i would've seen the exception with PostgreSQL, instead of discovering it with a MySQL setup. thank you both for your prompt reply. i'll try aliasing the aggregate function and will get back to you. also, thank you David for writing such an elegant piece of code, and making it available, for free. cheers; rsn -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Que du magnifique iD8DBQFBp4hy+e1AKnsTRiERAwmZAJ9vRFku1e8cKG4xtFTWZA8JTzHm9QCg0pzy MPe5SdYqAbQswBfTpGjM2qE= =wOk9 -----END PGP SIGNATURE-----