The OBJECT_ID_FROM_NODE_ID function

This function extracts the object_id from a given node_id. The following code returns the object_id for the dbo.TwitterUser node table:

SELECT OBJECT_ID_FROM_NODE_ID('{"type":"node","schema":"dbo","table":"TwitterUser","id":0}');

It parses the input string, extracts the schema and table name, and returns the object_id if all these criteria are fulfilled:

  • The input string is a JSON conforming string
  • A node table exists with the extracted table name in the extracted schema
  • The key id has a bigint value (a node_id with this value does not need to exist in the node table)

The following code will still return the correct object_id, even though there is no entry in the node table with the value 567890 for the graph_id column:

SELECT OBJECT_ID_FROM_NODE_ID('{"type":"node","schema":"dbo","table":"TwitterUser","id":567890}');

If the input string is not JSON conforming or NULL, the function returns NULL, as shown in the following code:

SELECT OBJECT_ID_FROM_NODE_ID('abc');
SELECT OBJECT_ID_FROM_NODE_ID('');
SELECT OBJECT_ID_FROM_NODE_ID(NULL);

Here is the output for the previous calls:

-----------
NULL

-----------
NULL

-----------
NULL

 The function returns an exception if you provide a non-string input, as in the following example:

SELECT OBJECT_ID_FROM_NODE_ID(1);

Here is the output:

Msg 8116, Level 16, State 1, Line 16
Argument data type int is invalid for argument 1 of object_id_from_node_id function.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.171.168