question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CREATE FUNCTION with PARAMETERS - bug in documentation or functionality?

See original GitHub issue

What 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:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pkoppsteincommented, Dec 7, 2015

By trial and error, I found that the key is the humble colon:

CREATE FUNCTION get "SELECT FROM V WHERE name = :VAL" PARAMETERS [VAL] LANGUAGE SQL IDEMPOTENT TRUE;

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.

0reactions
MBharucommented, May 12, 2020

Also, kindly provide the syntax to drop/delete a user-defined function from console.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found