CREATE FUNCTION with PARAMETERS - bug in documentation or functionality?
See original GitHub issueWhat is the correct syntax for creating an SQL function with a named parameter?
The documentation at http://orientdb.com/docs/2.1/SQL-Create-Function.html is not very clear about how the named parameter should be used in the function body.
I have tried numerous variants of the following:
CREATE FUNCTION get "SELECT FROM Person WHERE name = ?" PARAMETERS [VAL] LANGUAGE SQL;
The function is successfully defined, but cannot be successfully used.
Consider for example this transcript:
OrientDB console v.2.1.5 (build 2.1.x@r; 2015-10-29 16:54:25+0000) www.orientdb.com
...
orientdb {db=diner}> SELECT count(*) FROM Person WHERE name = "Bill"
----+------+-----
# |@CLASS|count
----+------+-----
0 |null |1
----+------+-----
1 item(s) found. Query executed in 0.002 sec(s).
orientdb {db=diner}> CREATE FUNCTION get "SELECT FROM Person WHERE name = ?" PARAMETERS [VAL] LANGUAGE SQL;
Function created successfully with id=#6:34
orientdb {db=diner}> select get("Bill")
----+------+----
# |@CLASS|get
----+------+----
0 |null |[0]
----+------+----
Note: For JAVASCRIPT functions, the situation is different, because one can (for example) write:
CREATE FUNCTION get 'return orient.getDatabase().query("select count(*) from " + val)[0]' PARAMETERS [val] LANGUAGE JAVASCRIPT
Thanks!
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Define a function with parameters - Studio Code.org
A function that does not explicitly return a value returns the JavaScript value undefined. Found a bug in the documentation? Let us know...
Read more >Argument labels before parameters in functions - possible bug ...
I always found that a little strange, but my guess is that the "external parameter name" acts as a label for the call...
Read more >15-410 Coding Style and Doxygen Documentation
This needs to be followed with a bugs section with a list of known bugs using the @bug command. If there are no...
Read more >Defining Your Own Python Function
How functions work in Python and why they're beneficial; How to define and call your ... the function to document what the appropriate...
Read more >4. More Control Flow Tools — Python 3.11.1 documentation
Create a sample collection users = {'Hans': 'active', ... Later we will see more functions that return iterables and take iterables as arguments....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
By trial and error, I found that the key is the humble colon:
So this is a documentation issue/bug.
Unfortunately, the result of calling get(_) is not quite the same as the result obtained calling SELECT directly. Documentation about that, I believe, is also needed.
Also, kindly provide the syntax to drop/delete a user-defined function from console.