Thread: OT - select + must have from - sql standard syntax?

OT - select + must have from - sql standard syntax?

From
Antoine
Date:
Hi,
I don't have a copy of the standard on hand and a collegue is claiming
that there must be a from clause in a select query (he is an oracle
guy). This doesn't seem to be the case for postgres... does anyone
know?
Cheers
Antoine
ps. any one of them will do...
--
This is where I should put some witty comment.

Re: OT - select + must have from - sql standard syntax?

From
"Jim C. Nasby"
Date:
On Tue, Jun 13, 2006 at 02:43:45PM +0200, Antoine wrote:
> Hi,
> I don't have a copy of the standard on hand and a collegue is claiming
> that there must be a from clause in a select query (he is an oracle
> guy). This doesn't seem to be the case for postgres... does anyone
> know?

Dunno, but I know that other databases (at least DB2) don't require FROM
either. In Oracle, if you want to do something like

SELECT now();

you actually have to do

SELECT now() FROM dual;

where dual is a special, hard-coded table in Oracle that has only one
row. Personally, I find their approach to be pretty stupid.
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

Re: OT - select + must have from - sql standard syntax?

From
Tom Lane
Date:
"Jim C. Nasby" <jnasby@pervasive.com> writes:
> On Tue, Jun 13, 2006 at 02:43:45PM +0200, Antoine wrote:
>> I don't have a copy of the standard on hand and a collegue is claiming
>> that there must be a from clause in a select query (he is an oracle
>> guy). This doesn't seem to be the case for postgres... does anyone
>> know?

> Dunno, but I know that other databases (at least DB2) don't require FROM
> either.

The spec does require a FROM clause in SELECT (at least as of SQL99, did
not check SQL2003).  However, it's clearly mighty useful to allow FROM
to be omitted for simple compute-this-scalar-result problems.  You
should respond to the Oracle guy that "SELECT whatever FROM dual" is not
in the standard either (certainly the spec does not mention any such
table).  And in any case an Oracle fanboy has got *no* leg to stand on
when griping about proprietary extensions to the spec.

            regards, tom lane

Re: OT - select + must have from - sql standard syntax?

From
Greg Stark
Date:
Tom Lane <tgl@sss.pgh.pa.us> writes:

> The spec does require a FROM clause in SELECT (at least as of SQL99, did
> not check SQL2003).  However, it's clearly mighty useful to allow FROM
> to be omitted for simple compute-this-scalar-result problems.  You
> should respond to the Oracle guy that "SELECT whatever FROM dual" is not
> in the standard either (certainly the spec does not mention any such
> table).

Well you could always create a "dual", it was always just a regular table. We
used to joke about what would happen to Oracle if you inserted an extra row in
it...

Oracle used to always require FROM, if it has stopped requiring it then that's
new. I had heard it had special-cased dual in later versions to avoid the
table access overhead, I suspect these two changes are related.

--
greg

Re: OT - select + must have from - sql standard syntax?

From
Antoine
Date:
> > The spec does require a FROM clause in SELECT (at least as of SQL99, did
> > not check SQL2003).  However, it's clearly mighty useful to allow FROM
> > to be omitted for simple compute-this-scalar-result problems.  You
> > should respond to the Oracle guy that "SELECT whatever FROM dual" is not
> > in the standard either (certainly the spec does not mention any such
> > table).

Thanks for your answers guys. I was pretty sure DUAL wasn't in the
standard (never seen it outside an oracle context) but wasn't at all
sure about the FROM.
Cheers
Antoine
ps. shame the standard isn't "freely" consultable to save you guys
silly OT questions!


--
This is where I should put some witty comment.

Re: OT - select + must have from - sql standard syntax?

From
"Dave Dutcher"
Date:
> -----Original Message-----
> From: pgsql-performance-owner@postgresql.org
> [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of
> Greg Stark
> Sent: Tuesday, June 13, 2006 11:16 PM
> Subject: Re: [PERFORM] OT - select + must have from - sql
> standard syntax?
[SNIP]
>
> Well you could always create a "dual", it was always just a
> regular table. We
> used to joke about what would happen to Oracle if you
> inserted an extra row in
> it...


I've never used Oracle, so I don't understand why its called dual when
it only has one row?  Shouldn't it be called single?  :\


Dave


Re: OT - select + must have from - sql standard syntax?

From
Tom Lane
Date:
Antoine <melser.anton@gmail.com> writes:
> ps. shame the standard isn't "freely" consultable to save you guys
> silly OT questions!

You can get free "draft" versions that are close-enough-to-final to be
perfectly usable.  See our developers' FAQ for some links.  I like the
drafts partly because they're plain ASCII, and so far easier to search
than PDFs ...

            regards, tom lane

Re: OT - select + must have from - sql standard syntax?

From
Antoine
Date:
> You can get free "draft" versions that are close-enough-to-final to be
> perfectly usable.  See our developers' FAQ for some links.  I like the
> drafts partly because they're plain ASCII, and so far easier to search
> than PDFs ...

Great to know - thanks!
Cheers
Antoine

--
This is where I should put some witty comment.