Re: Am I crazy or is this SQL not possible

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Yasir Malik <ymalik(at)cs(dot)stevens(dot)edu>
Cc: PostgreSQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Am I crazy or is this SQL not possible
Date: 2006-06-01 19:54:59
Message-ID: 1149191698.25526.147.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Chris Browne 2006-06-01 19:56:00 Re: Table design question
Previous Message Alvaro Herrera 2006-06-01 19:54:05 Re: Am I crazy or is this SQL not possible