Regarding niladic functions

Started by Chandra Sekhar Surapaneniabout 21 years ago4 messagesgeneral
Jump to latest
#1Chandra Sekhar Surapaneni
chandu@positivenetworks.net

Hi All,
Can we write our own niladic functions in 8.0.0? I want to write a
niladic function similar to current_timestamp, but I did not find any
information in the documentation. Thank you for your time
Regards
chandu

#2Neil Conway
neilc@samurai.com
In reply to: Chandra Sekhar Surapaneni (#1)
Re: Regarding niladic functions

Chandra Sekhar Surapaneni wrote:

Can we write our own niladic functions in 8.0.0? I want to write a
niladic function similar to current_timestamp, but I did not find any
information in the documentation.

If you mean a function without any arguments, it is trivial:

CREATE FUNCTION foo() RETURNS ... AS ...;
SELECT foo();

If you mean a function that doesn't take any arguments and can be
invoked without an empty set of parentheses (like current_timestamp),
there isn't a way to define such a function via SQL. You could probably
hack the SQL parser to add support for specific functions like this, as
is done for current_timestamp and friends.

-Neil

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Neil Conway (#2)
Re: Regarding niladic functions

Neil Conway <neilc@samurai.com> writes:

If you mean a function that doesn't take any arguments and can be
invoked without an empty set of parentheses (like current_timestamp),
there isn't a way to define such a function via SQL. You could probably
hack the SQL parser to add support for specific functions like this, as
is done for current_timestamp and friends.

It would in fact *require* a parser change, which is why we don't
support it.

(Personally I think it was tremendously stupid of the SQL committee
to define these things as keywords rather than functions, anyway ...
as is, they conflict with column names, which they would not do if
they were invoked as foo() ...)

regards, tom lane

#4Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#3)
Re: Regarding niladic functions (another form)

Hello,

It's not really about subject - sorry. I tryed implement support of XML.
For it I need functions which know names of params.

example:
create table foo(a integer);
select xmlnode(a) from foo; -> <a>10</a> ....
select xmlnode(a as b) from foo; -> <b>10</b> ...

I have particular solution, but maybe is better general support for it.
There is some ideas about functions with variable count of params?

Thank You
Pavel Stehule