X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 4DA429FA5C8 for ; Thu, 1 Jun 2006 16:55:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 59623-03 for ; Thu, 1 Jun 2006 16:55:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id E95CF9FA040 for ; Thu, 1 Jun 2006 16:55:00 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Thu, 1 Jun 2006 19:54:59 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 01 Jun 2006 14:54:59 -0500 Subject: Re: Am I crazy or is this SQL not possible From: Scott Marlowe To: Yasir Malik Cc: PostgreSQL In-Reply-To: References: <447F34B1.5020004@oisinglynn.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1149191698.25526.147.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 01 Jun 2006 14:54:59 -0500 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/26 X-Sequence-Number: 25262 On Thu, 2006-06-01 at 14:47, Yasir Malik wrote: > > It is a hack, but when someone wants you to do something in a way > > different from the norm, aren't they asking for a hack? > > > > SQL Server does something like > > select top (1) from .... > > > > I am thinking this is NOT a SQL-99 standard. > > > This was an interview with Amazon, and I don't think Amazon wanted a hack. > I hope Amazon doesn't use hacks. There has to be another way. It would > be cruel if they expected me know some database specific functionality. > Here's what I gave them: > select value > from table t > where t.value > > (select t2.value > from table t2); > > which would be fine if the sub-select returned simply a list, but that > isn't even valid SQL (I didn't get the job, BTW). Sometimes the only reasonable answer is a hack. Much like in the older versions of PostgreSQL where select max(id) from sometable was slower than watching grass grow, the standard "hack" was to do select id from sometable order by id desc limit 1. If the SQL way kills your server and the hack doesn't, you use the hack and move on.