Indexes on Expressions -- Parentheses

Started by Thomas F.O'Connellover 21 years ago13 messagesdocsgeneral
Jump to latest
#1Thomas F.O'Connell
tfo@sitening.com
docsgeneral

From 11.5 in the docs:

"The syntax of the CREATE INDEX command normally requires writing
parentheses around index expressions, as shown in the second example.
The parentheses may be omitted when the expression is just a function
call, as in the first example."

But when I try this:

db=# CREATE INDEX expression_idx on some_table( extract( year from
some_column ) );

I get a syntax error corresponding to the open parenthesis after
extract (and whitespace is not the issue).

If I add an enclosing set of parentheses, E.g.:

db=# CREATE INDEX expression_idx on some_table( ( extract( year from
some_column ) ) );

it works!

Is this a known issue?

-tfo

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Thomas F.O'Connell (#1)
docsgeneral
Re: Indexes on Expressions -- Parentheses

sszabo@bigpanda.com

On Tue, 28 Sep 2004, Thomas F.O'Connell wrote:

From 11.5 in the docs:

"The syntax of the CREATE INDEX command normally requires writing
parentheses around index expressions, as shown in the second example.
The parentheses may be omitted when the expression is just a function
call, as in the first example."

But when I try this:

db=# CREATE INDEX expression_idx on some_table( extract( year from
some_column ) );

Extract(year from some_column) is not really just a function call it's
an expression that looks similar to a function call because that's how SQL
defined it.

#3Thomas F.O'Connell
tfo@sitening.com
In reply to: Stephan Szabo (#2)
docsgeneral
EXTRACT Clarification

Switching this thread to DOCS and renaming it...

Anyway, I think that this situation calls for some clarification in the
docs. If others agree, I'd be happy to submit a potential patch.

I'm thinking something like this (with thanks to Stephan):

Note: EXTRACT is not a true function. SQL defines it as an expression
that happens to look similar to a function call.

Is this wording acceptable? I'd imagine putting it at the end of 9.8.1.

Also, are there other expressions that fall into this category? I don't
know the spec well enough to know.

-tfo

On Sep 29, 2004, at 1:30 AM, Stephan Szabo wrote:

Show quoted text

sszabo@bigpanda.com

On Tue, 28 Sep 2004, Thomas F.O'Connell wrote:

From 11.5 in the docs:

"The syntax of the CREATE INDEX command normally requires writing
parentheses around index expressions, as shown in the second example.
The parentheses may be omitted when the expression is just a function
call, as in the first example."

But when I try this:

db=# CREATE INDEX expression_idx on some_table( extract( year from
some_column ) );

Extract(year from some_column) is not really just a function call it's
an expression that looks similar to a function call because that's how
SQL
defined it.

#4Kris Jurka
books@ejurka.com
In reply to: Thomas F.O'Connell (#3)
docsgeneral
Re: EXTRACT Clarification

On Wed, 29 Sep 2004, Thomas F.O'Connell wrote:

Note: EXTRACT is not a true function. SQL defines it as an expression
that happens to look similar to a function call.

Also, are there other expressions that fall into this category? I don't
know the spec well enough to know.

At least COALESCE and NULLIF are not functions.

Kris Jurka

#5Thomas F.O'Connell
tfo@sitening.com
In reply to: Kris Jurka (#4)
docsgeneral
Re: EXTRACT Clarification

It seems like it would be worth noting these (and any others) in the
docs in some way. Is there a way for someone without a copy of the spec
to be aware of which are functions and which are not, otherwise?

-tfo

On Sep 29, 2004, at 9:25 AM, Kris Jurka wrote:

Show quoted text

On Wed, 29 Sep 2004, Thomas F.O'Connell wrote:

Note: EXTRACT is not a true function. SQL defines it as an expression
that happens to look similar to a function call.

Also, are there other expressions that fall into this category? I
don't
know the spec well enough to know.

At least COALESCE and NULLIF are not functions.

Kris Jurka

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas F.O'Connell (#3)
docsgeneral
Re: EXTRACT Clarification

"Thomas F.O'Connell" <tfo@sitening.com> writes:

I'm thinking something like this (with thanks to Stephan):

Note: EXTRACT is not a true function. SQL defines it as an expression
that happens to look similar to a function call.

Rather than documenting this, maybe we should change the grammar to
allow it?

regards, tom lane

#7Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Tom Lane (#6)
docsgeneral
Re: EXTRACT Clarification

On Wed, 29 Sep 2004, Tom Lane wrote:

"Thomas F.O'Connell" <tfo@sitening.com> writes:

I'm thinking something like this (with thanks to Stephan):

Note: EXTRACT is not a true function. SQL defines it as an expression
that happens to look similar to a function call.

Rather than documenting this, maybe we should change the grammar to
allow it?

That would work, but presumably then we should be doing all the function
looking things, so probably CAST, EXTRACT, OVERLAY, POSITION, SUBSTRING,
TREAT, TRIM, CONVERT (and any, if any, that weren't in the section of the
grammar I saw those).

#8Thomas F.O'Connell
tfo@sitening.com
In reply to: Tom Lane (#6)
docsgeneral
Re: EXTRACT Clarification

That seems reasonable, too, although I was interested to learn that
this (and a few other expressions) weren't actually functions. Whether
that's actually meaningful for any implementation purposes is
debatable.

Even if the grammar is changed to allow it, it's probably worth making
a note of it in SQL compatibility documentation.

Speaking of which, since functions aren't in the SQL Commands
reference, where the compatibility documentation resides, does anyone
see value in adding compatibility information to The SQL Language
section as a whole?

I can contribute what I know, but I don't have a full copy of the spec.

-tfo

On Sep 29, 2004, at 11:32 AM, Tom Lane wrote:

Show quoted text

"Thomas F.O'Connell" <tfo@sitening.com> writes:

I'm thinking something like this (with thanks to Stephan):

Note: EXTRACT is not a true function. SQL defines it as an expression
that happens to look similar to a function call.

Rather than documenting this, maybe we should change the grammar to
allow it?

regards, tom lane

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas F.O'Connell (#8)
docsgeneral
Re: EXTRACT Clarification

"Thomas F. O'Connell" <tfo@sitening.com> writes:

That seems reasonable, too, although I was interested to learn that
this (and a few other expressions) weren't actually functions.

They are functions ... but not from the point of view of the grammar,
which has special productions for them to cope with SQL's whimsical
syntax requirements.

regards, tom lane

#10Thomas F.O'Connell
tfo@sitening.com
In reply to: Tom Lane (#9)
docsgeneral
Re: EXTRACT Clarification

Ah, so it's really a question of whether the syntactic sugar of CREATE
INDEX is considered worthwhile by the developers (rather than a
standards compliance issue) because CREATE INDEX is not a part of the
SQL spec?

Now that I understand what's going on, I don't have a strong
preference, but I'd say that either it needs noting in the
documentation or it should be added to the grammar.

And if it isn't going to hit the grammar for 7.4.x, I'd be happy to
supply a doc patch.

-tfo

On Sep 29, 2004, at 12:09 PM, Tom Lane wrote:

Show quoted text

"Thomas F. O'Connell" <tfo@sitening.com> writes:

That seems reasonable, too, although I was interested to learn that
this (and a few other expressions) weren't actually functions.

They are functions ... but not from the point of view of the grammar,
which has special productions for them to cope with SQL's whimsical
syntax requirements.

regards, tom lane

#11Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas F.O'Connell (#10)
docsgeneral
Re: EXTRACT Clarification

"Thomas F. O'Connell" <tfo@sitening.com> writes:

Ah, so it's really a question of whether the syntactic sugar of CREATE
INDEX is considered worthwhile by the developers (rather than a
standards compliance issue) because CREATE INDEX is not a part of the
SQL spec?

Right. It is not a SQL-compliance item because CREATE INDEX isn't in
the standard in the first place.

The fact that the CREATE INDEX syntax allows for some things that look
like function calls but not for other things that look like function
calls is an annoyance, no doubt about it. I'm not sure how important
it is to fix though.

regards, tom lane

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#11)
docsgeneral
Re: EXTRACT Clarification

The fact that the CREATE INDEX syntax allows for some things that look
like function calls but not for other things that look like function
calls is an annoyance, no doubt about it. I'm not sure how important
it is to fix though.

Turns out to be easy to fix in the grammar, so I did it.

regards, tom lane

#13Thomas F.O'Connell
tfo@sitening.com
In reply to: Tom Lane (#12)
docsgeneral
Re: EXTRACT Clarification

Nice. Thanks. My guess is that because this problem has existed until
now there's no point in adding any notes to the 7.4.x docs?

-tfo

On Sep 29, 2004, at 7:46 PM, Tom Lane wrote:

Show quoted text

The fact that the CREATE INDEX syntax allows for some things that look
like function calls but not for other things that look like function
calls is an annoyance, no doubt about it. I'm not sure how important
it is to fix though.

Turns out to be easy to fix in the grammar, so I did it.

regards, tom lane