Thread: Functions vs. Columns?????
Hi, I have a question as to how postgres handles some built-in functions, for example: Works Doesn't Work ------ ------------ select now(); select now; select current_date; select current_date(); It seems that there should be some consistency here in the use of parenthesis. I don't really know how these things are handled on the backend, but it seems that parenthesis are the more correct way, or at least both should be allowed. Any thoughts? Byron
> -----Original Message----- > From: owner-pgsql-interfaces@postgreSQL.org > [mailto:owner-pgsql-interfaces@postgreSQL.org]On Behalf Of Byron > Nikolaidis > > Hi, > > I have a question as to how postgres handles some built-in functions, > for example: > > Works Doesn't Work > ------ ------------ > select now(); select now; > select current_date; select current_date(); > > It seems that there should be some consistency here in the use of > parenthesis. I don't really know how these things are handled on the > backend, but it seems that parenthesis are the more correct way, or at > least both should be allowed. > > Any thoughts? > Parenthesis are needed in order to call functions in PostgreSQL. current_date isn't a built-in function of PostgreSQL. It's an SQL standard function and it's a special work of PostgreSQL parser to change current_date to call another built-in function. Regards. Hiroshi Inoue Inoue@tpf.co.jp
Byron Nikolaidis <byron.nikolaidis@home.com> writes: > Works Doesn't Work > ------ ------------ > select now(); select now; > select current_date; select current_date(); > It seems that there should be some consistency here in the use of > parenthesis. Consistency? Who needs consistency ;-) ? What you're seeing here is the conflict of two cultures. The SQL92 standard mandates a keyword CURRENT_DATE, with *no* parentheses, as the way to get the current date. now() comes out of the Berkeley Postquel code, which inherits from an academic tradition that doesn't like inventing reserved words without need, and also thinks that things that look like constants ought to *be* constants. The way to resolve that tension, in academese, is to invent parameterless functions. But the folks who wrote the SQL92 spec seem to have been raised on COBOL, which never met a reserved word it didn't like. Anyway, Postgres supports both the SQL92 notation and the notation we inherited from Postquel. I don't think that adding with-or- without-parentheses-take-your-pick-for-both syntax freedom would be a step forward... that path leads to way too many traps for the unwary programmer. regards, tom lane
> It seems that there should be some consistency here in the use of > parenthesis. I don't really know how these things are handled on the > backend, but it seems that parenthesis are the more correct way, or at > least both should be allowed. The ones without parens are SQL-mandated "constants" which are translated in the parser front end into function calls (usually with some other name for historical reasons). Other function calls, like now(), are really that: function calls. > Any thoughts? Uh, sure ;) - Thomas -- Thomas Lockhart lockhart@alumni.caltech.edu South Pasadena, California