RETURN @rid doesn't work as documented

117 views
Skip to first unread message

Eric24

unread,
Jun 2, 2016, 12:28:38 AM6/2/16
to OrientDB
When I do the following (or any other SQL INSERT or UPDATE operation that supports the RETURN clause), I get the full record back, not just the RID:

INSERT INTO VMenu CONTENT {"Main":"PM", "Timeout":"PT", "Error":"PE"} RETURN @rid

How can I get just the newly-created (or update) RID? I need to use it in the next SQL statement in the function.


Message has been deleted

user.w...@gmail.com

unread,
Jun 2, 2016, 2:20:31 AM6/2/16
to OrientDB
Hi Eric,

try this:

INSERT INTO VMenu CONTENT {"Main":"PM", "Timeout":"PT", "Error":"PE"} return @class

this is the output:


Hope it helps.


Regards,

Michela


Eric24

unread,
Jun 2, 2016, 8:44:39 AM6/2/16
to OrientDB
Well, if I use RETURN @rid, I get the whole record back. Using RETURN @class, I get back what you show in your example, which is still a JSON object that contains the RID. But I was expecting RETURN @rid to return just the RID as a simple string. In any case, there is no different between RETURN [BEFORE|AFTER] @rid and having no RETURN clause--both return the full record that was inserted, so unless I'm totally misinterpreting the documentation, this looks like a bug.

alessand...@gmail.com

unread,
Jun 6, 2016, 3:46:48 AM6/6/16
to orient-...@googlegroups.com
Hi Eric,
you should use this query

INSERT INTO VMenu CONTENT {"Main":"PM", "Timeout":"PT", "Error":"PE"} RETURN @rid.asString()



Kind regards,
Alessandro

Eric Lenington

unread,
Jun 6, 2016, 8:40:48 AM6/6/16
to OrientDB
Thank you, but actually, that doesn't get me what I'm looking for. True, rid is a string in the JSON, but I'm still not able to get the rid as a simple variable. What is need is just "#xx:yy", not part of a JSON structure. In one attempt at a Javascript function, I used variations of result[0]."@rid" and wasn't able to get it to work. Are you suggesting that result[0]."rid" or .rid with the .asString() option is the solution?

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/en8zNxWtC88/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

alessand...@gmail.com

unread,
Jun 6, 2016, 10:18:21 AM6/6/16
to OrientDB
Hi Eric,
I hope that this javascript function could be helpful for you.

var g=orient.getGraph();
var b=g.command("sql","INSERT INTO VMenu CONTENT {'Main':'PM', 'Timeout':'PT', 'Error':'PE'} RETURN @rid");
g
.commit();
var query="update "+ b.getId().toString() + " set newProperty='NP'";
g
.command("sql",query);

Let me know.

Best regards,
Alessandro

Eric Lenington

unread,
Jun 6, 2016, 10:53:01 AM6/6/16
to OrientDB
This is very helpful, but how do you know the properties/functions available on 'orient', 'g', and 'b' (i.e. command, commit, getId, etc.)? I can't find this documented anywhere, short of a few examples here and there (some of which conflict with each other)? Also, I'm assuming that this is the syntax for a custom JS function?


--

alessand...@gmail.com

unread,
Jun 6, 2016, 11:03:46 AM6/6/16
to OrientDB
Hi Eric,
you can look this link.

Alessandro

scott molinari

unread,
Jun 6, 2016, 11:52:39 AM6/6/16
to OrientDB
I also found this:

http://orientdb.com/docs/last/Functions-Creation.html

Check the other sections in the menu too.

Scott

Eric Lenington

unread,
Jun 6, 2016, 12:41:10 PM6/6/16
to OrientDB
Thank you. Very interesting. The first link is very useful, but it was apparently removed from the current documentation. Wonder why...

The second link is one I've seen, but it's more high-level, focused on the process of creating functions in Studio.

--

scott molinari

unread,
Jun 6, 2016, 2:15:05 PM6/6/16
to OrientDB
Did you look through the other links in the menu under "Functions"? Not sure that info will help, but it does go into a little more detail about functions.

Scott

Eric Lenington

unread,
Jun 6, 2016, 11:43:34 PM6/6/16
to OrientDB
Yes, but unless I'm totally missing it, neither the old or the new documentation really document the custom JS function environment. There are some code examples that use some of the objects and functions, but, for example (from Alessandro's example code), getId() and commit() are not documented anywhere that I could find. While I can probably guess what commit() does (although that doesn't really tell me the whole story--does it need a corresponding begin(); is there a cancel() or rollback()?; etc.), I'm not sure how I should guess that getId() even exists or how I should know to use it. That's the frustrating part--projects that should take less than an hour end up taking hours or days due to having to learn the environment by trial-and-error. I'm probably beating a dead horse here, but I really do hope ODB makes documentation a higher priority going forward.

On Mon, Jun 6, 2016 at 1:15 PM, 'scott molinari' via OrientDB <orient-...@googlegroups.com> wrote:
Did you look through the other links in the menu under "Functions"? Not sure that info will help, but it does go into a little more detail about functions.

Scott

--

scott molinari

unread,
Jun 7, 2016, 3:04:01 AM6/7/16
to OrientDB
Yeah, I see what you mean. I wonder if digging into the ODB code (although shouldn't be necessary) might get you some more details?

I believe this is the area of ODB that works the JS functions...(but, it is just a big guess on my part).

Eric Lenington

unread,
Jun 7, 2016, 10:01:02 AM6/7/16
to OrientDB
Ugh and sigh. I had considered that (and tried it for a short time), but ultimately decided I didn't have the bandwidth to go through that learning curve.

--
Reply all
Reply to author
Forward
0 new messages