"VirtSPARQLOptGuideEx2" . . . "2017-06-13T05:35:59Z" . . . "2017-06-13T05:35:59Z" . "%META:TOPICPARENT{name=\"VirtTipsAndTricksGuide\"}%\n---+ Generating a Unique ID via SPARQL HTTP\n\nSuppose you need unique IDs from within Virtuoso (unique only to a given Virtuoso instance/cluster \nwould suffice), and that this should be done via SPARQL HTTP prior to issuing a SPARQL insert.\n\nOne solution would be to create a table and procedure that keeps track of an incremental ID and \nreturns each ID only once. Then you can access this procedure via SPARQL HTTP by using:\n\n( \n SELECT ( bif:foo() ) AS ?id \n WHERE \n { \n ?s ?p ?o \n } limit 1 \n)\n\n\n---++ An optimized solution\n\nVirtuoso's built-in functions (BIFs) [[http://docs.openlinksw.com/virtuoso/fn_sequence_next.html][sequence_next()]] \nand [[http://docs.openlinksw.com/virtuoso/sequenceobjects.html][sequence_set()]]\nwill streamline this task. \n\nLike any other SQL functions without INOUT or OUT parameters, these can be called from SPARQL \nsimply as bif:sequence_next() or bif:sequence_set(),\nbut an IN parameter may be used to get one sequence per graph, i.e., \nbif:sequence_next(\"GRAPH_IDENTIFIER\"), e.g., \nbif:sequence_next(\"<http://my.example.com/graph1>\").\n\n\n\nSQL> SPARQL \n INSERT INTO GRAPH \n { \n <:a> <:p> `bif:sequence_next(\"\")` \n } ;\n\ncallret-0\nVARCHAR\n_______________________________________________________________________________\n\nInsert into , 1 (or less) triples -- done\n\n1 Rows. -- 141 msec.\nSQL> SPARQL \n INSERT INTO GRAPH \n {\n <:a> <:p> `bif:sequence_next(\"\")` \n } ;\n\ncallret-0\nVARCHAR\n_______________________________________________________________________________\n\nInsert into , 1 (or less) triples -- done\n\n1 Rows. -- 4 msec.\nSQL> SPARQL \n SELECT * \n FROM \n WHERE\n { \n ?s ?p ?o \n }\n ;\n\ns p o\nVARCHAR VARCHAR VARCHAR\n_______________________________________________________________________________\n\n:a :p 0\n:a :p 1\n\n2 Rows. -- 1 msec.\nSQL> \n\n\n---++ Side-note -- bif: prefix vs. sql: prefix\n\nFor user-defined functions, the sql: prefix is preferred over \nthe bif: prefix; e.g.,\n\nsql:foo(x) \n\n-- will call --\n\nDB.DBA.foo(x)\n\nThe difference is that bif:foo will make an unqualified call to foo(). \nIf no built-in function foo() exists, and the system contains many users and database \nqualifiers, the search for exact name of XXX.YYY.foo() adds needless overhead. \nFurther issues may arise if multiple XXX.YYY.foo() procedures have been defined.\n\n \n---++ Related\n\n * [[VirtSPARQLOptGuide][Virtuoso SPARQL Optimization Guide]]" . . . . "VirtSPARQLOptGuideEx2" . "e9171d8c23180404b2318808dc2066bf" . . . "VirtSPARQLOptGuideEx2" . "2017-06-13T05:35:59.109053"^^ . . "2017-06-13T05:35:59.109053"^^ . . . . . . .