{"id":13258,"date":"2022-05-26T12:05:50","date_gmt":"2022-05-26T19:05:50","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=13258"},"modified":"2025-06-13T23:34:35","modified_gmt":"2025-06-14T06:34:35","slug":"traverse-hierarchy-user-defined-functions-in-7-1","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/ko\/traverse-hierarchy-user-defined-functions-in-7-1\/","title":{"rendered":"SQL++ \uc0ac\uc6a9\uc790 \uc815\uc758 \ud568\uc218(UDF)\ub97c \uc0ac\uc6a9\ud55c \ud2b8\ub798\ubc84\uc2a4 \uacc4\uce35 \uad6c\uc870"},"content":{"rendered":"<p><span style=\"font-weight: 400\">User-defined functions (UDFs) are a feature that exist in most RDBMS. Whether it is Oracle PL\/SQL (Procedural Language for SQL), SQL Server T-SQL (Transact-SQL), PL\/pgSQL (Procedural Language\/PostgreSQL), or other variants, all these languages have the general characteristics of providing<\/span><span style=\"font-weight: 400\"> a block structure, condition control, iteration loop, and error handling. These building blocks allow the development of complex tasks, which can be isolated to improve maintenance and application integrity.<\/span><\/p>\n<p><span style=\"font-weight: 400\">For Couchbase, the criteria in choosing the language for <a href=\"https:\/\/www.couchbase.com\/sqlplusplus\/\">SQL++<\/a> User Defined Functions is quite clear\u2013 they must be able to support all the capabilities that exist in the current RDBMS implementations or to the same level that Couchbase Query service can, and also reflect the preference of today&#8217;s developers. According to Stack Overflow developer surveys, the most commonly used programming language in the world as of 2020 is <\/span><b>JavaScript<\/b><span style=\"font-weight: 400\">.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">SQL++ UDF\/JS<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Couchbase is a document database that natively stores its data in JSON format (<\/span><b>J<\/b><span style=\"font-weight: 400\">ava<\/span><b>S<\/b><span style=\"font-weight: 400\">cript <\/span><b>O<\/b><span style=\"font-weight: 400\">bject <\/span><b>N<\/b><span style=\"font-weight: 400\">otation). Its query language, SQL++ , is <em>SQL for JSON<\/em>. The JavaScript language is therefore the most natural way to access and manipulate JSON data.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Please refer to Couchbase documentation for more details on the <a href=\"https:\/\/docs.couchbase.com\/server\/current\/eventing\/eventing-language-constructs.html\" target=\"_blank\" rel=\"noopener\">full implementation of JavaScript in Couchbase<\/a>.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">The JavaScript UDF to traverse trees<\/span><\/h3>\n<p><span style=\"font-weight: 400\">JavaScript is powerful, flexible, and relatively easy to start using. To show its versatility, I created a Javascript UDF for this article that traverses a tree structure, such as an organizational structure.<\/span><\/p>\n<p>UDF: <em>traverseTree<\/em><\/p>\n<p><span style=\"font-weight: 400\">The UDF performs a recursive search on a collection using the two <em>connect<\/em> fields (to and from) for the recursion.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Parameters are shown in the following table:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>#<\/strong><\/td>\n<td><strong>Name<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1<\/span><\/td>\n<td><i><span style=\"font-weight: 400\">kSpace<\/span><\/i><\/td>\n<td><span style=\"font-weight: 400\">The key space for the query. This could be a collection or query.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2<\/span><\/td>\n<td><i><span style=\"font-weight: 400\">startWith<\/span><\/i><\/td>\n<td><span style=\"font-weight: 400\">Start the search with this value for the connectToFld. If empty, the search will be performed for all connectTo values<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3<\/span><\/td>\n<td><i><span style=\"font-weight: 400\">connectTo<\/span><\/i><\/td>\n<td><span style=\"font-weight: 400\">The name of the field in the collection where the connectTo field will be used<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4<\/span><\/td>\n<td><i><span style=\"font-weight: 400\">connectFrom<\/span><\/i><\/td>\n<td><span style=\"font-weight: 400\">The name of the field in the collection where the connectFrom field will be used<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5<\/span><\/td>\n<td><i><span style=\"font-weight: 400\">reportHier<\/span><\/i><\/td>\n<td><span style=\"font-weight: 400\">The field name for the hierarchy array<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6<\/span><\/td>\n<td><i><span style=\"font-weight: 400\">logKSpace<\/span><\/i><\/td>\n<td><span style=\"font-weight: 400\">The key space where optional logging for UDF is written to. Please note this parameter can only run when run with EXECUTE FUNCTION.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><span style=\"font-weight: 400\">Examples of hierarchy<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Let&#8217;s consider an organizational hierarchy structure as below.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-13260\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/05\/traverse-org-chart-json-sql.png\" alt=\"traverse hierarchical data example\" width=\"307\" height=\"192\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/traverse-org-chart-json-sql.png 307w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/traverse-org-chart-json-sql-300x188.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/traverse-org-chart-json-sql-20x13.png 20w\" sizes=\"auto, (max-width: 307px) 100vw, 307px\" \/><\/p>\n<p><span style=\"font-weight: 400\">The <\/span><em><span style=\"font-weight: 400\">emp<\/span><\/em><span style=\"font-weight: 400\"> collection has the following documents:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:js decode:true \">[\r\n\u00a0 { \"empid\": 1, \"name\": \"JeffC\"\u00a0 \u00a0 },\r\n\u00a0 { \"empid\": 2, \"name\": \"SteveA\",\u00a0 \"reportsTo\": \"JeffC\" \u00a0 },\r\n\u00a0 { \"empid\": 3, \"name\": \"AmitG\", \u00a0 \"reportsTo\": \"JeffC\" \u00a0 },\r\n\u00a0 { \"empid\": 4, \"name\": \"BrendaM\", \"reportsTo\": \"SteveA\"\u00a0 },\r\n\u00a0 { \"empid\": 5, \"name\": \"WillG\", \u00a0 \"reportsTo\": \"SteveA\"\u00a0 },\r\n\u00a0 { \"empid\": 6, \"name\": \"PaulD\", \u00a0 \"reportsTo\": \"BrendaM\" }\r\n]<\/pre>\n<pre class=\"decode-attributes:false lang:default decode:true\">SELECT e.* FROM traverseTree('traversal.hierarchy.emp','','name','reportsTo','ReportHierarchy','') e;<\/pre>\n<p>The query produces the following results:<\/p>\n<pre class=\"decode-attributes:false lang:js decode:true\">[\r\n\u00a0 {\r\n\u00a0 \u00a0 \"ReportHierarchy\": [],\r\n\u00a0 \u00a0\"name\": \"JeffC\"\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"ReportHierarchy\": [ { \"level\": 1,\"name\": \"JeffC\" } ],\r\n\u00a0 \u00a0\"name\": \"SteveA\",\r\n\u00a0 \u00a0 \"reportsTo\": \"JeffC\"\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"ReportHierarchy\": [ { \"level\": 1,\"name\": \"JeffC\" } ],\r\n\u00a0 \u00a0\"name\": \"AmitG\",\r\n\u00a0 \u00a0 \"reportsTo\": \"JeffC\"\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"ReportHierarchy\": [ { \"level\": 1,\"name\": \"SteveA\",\"reportsTo\": \"JeffC\" },\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 { \"level\": 2,\"name\": \"JeffC\" }\u00a0 ],\r\n\u00a0 \u00a0\u00a0\"name\": \"BrendaM\",\r\n\u00a0 \u00a0 \"reportsTo\": \"SteveA\"\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"ReportHierarchy\": [ { \"level\": 1,\"name\": \"SteveA\",\"reportsTo\": \"JeffC\" },\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 { \"level\": 2,\"name\": \"JeffC\" }\u00a0 ],\r\n\u00a0 \u00a0 \"name\": \"WillG\",\r\n\u00a0 \u00a0 \"reportsTo\": \"SteveA\"\r\n\u00a0 },\r\n\u00a0 {\r\n\u00a0 \u00a0 \"ReportHierarchy\": [ { \"level\": 1,\"name\": \"BrendaM\",\"reportsTo\": \"SteveA\" },\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 { \"level\": 2,\"name\": \"SteveA\", \"reportsTo\": \"JeffC\"\u00a0 },\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 { \"level\": 3,\"name\": \"JeffC\" }\u00a0 ],\r\n\u00a0 \u00a0\"name\": \"PaulD\",\r\n\u00a0 \u00a0 \"reportsTo\": \"BrendaM\"\r\n\u00a0 }\r\n]\r\n<\/pre>\n<h3><span style=\"font-weight: 400\">Create the <\/span><em><span style=\"font-weight: 400\">traverseTree<\/span><\/em><span style=\"font-weight: 400\"> user-defined\u00a0 function<\/span><\/h3>\n<p><span style=\"font-weight: 400\">In Couchbase SQL++, a UDF can be defined in a number of ways.\u00a0<\/span><\/p>\n<h5>UDF as a scalar function<\/h5>\n<pre class=\"decode-attributes:false lang:default decode:true\">CREATE FUNCTION to_meters(...) { args[0] * 0.3048 };\r\n\r\nSELECT airportname, ROUND(to_meters(geo.alt)) AS mamsl\r\nFROM `travel-sample`.inventory.airport\r\nLIMIT 5;<\/pre>\n<p>&nbsp;<\/p>\n<h5>As an inline function with a subquery<\/h5>\n<pre class=\"decode-attributes:false lang:default decode:true\">CREATE FUNCTION locations(vActivity) { (\r\n\u00a0 SELECT id, name, address, city\r\n\u00a0 FROM `travel-sample`.inventory.landmark\r\n\u00a0 WHERE activity = vActivity) };\r\n\r\nSELECT l.name, l.city\r\nFROM locations(\"eat\") AS l\r\nWHERE l.city = \"Gillingham\";<\/pre>\n<p>&nbsp;<\/p>\n<h5>Defined as an external function<\/h5>\n<p><span style=\"font-weight: 400\">The <em>traverseTree<\/em> UDF uses the external function mechanism. But in this case, we provide the external code library for the function. Refer to the Couchbase documentation for more details on <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/userfun.html\" target=\"_blank\" rel=\"noopener\">External Function<\/a>.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Here\u2019s how to create a JavaScript function library:<\/span><\/p>\n<p><b>1- Create the function library<\/b><span style=\"font-weight: 400\"> &#8211; In this example, we use Query Workbench to create the JavaScript library.\u00a0<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-13261\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/05\/image2-2-1024x235.png\" alt=\"Managing JavaScript function libraries\" width=\"900\" height=\"207\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image2-2-1024x235.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image2-2-300x69.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image2-2-768x177.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image2-2-1536x353.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image2-2-20x5.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image2-2-1320x304.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image2-2.png 1948w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p><b>2 &#8211; Add and Edit the JavaScript code<\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-13262\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/05\/image4.png\" alt=\"Editing Couchbase JavaScript code\" width=\"646\" height=\"416\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image4.png 646w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image4-300x193.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image4-20x13.png 20w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/p>\n<p><span style=\"font-weight: 400\">Refer to this [<\/span><a href=\"https:\/\/github.com\/binhquocle\/Coding\/blob\/master\/udfs\/tree.js\"><span style=\"font-weight: 400\">link<\/span><\/a><span style=\"font-weight: 400\">] for the complete traverseTree JavaScript library code.<\/span><\/p>\n<p><b>3 &#8211; Create the SQL++ user-defined function<\/b><span style=\"font-weight: 400\">\u00a0<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">CREATE FUNCTION traverseTree(kSpace,startWith, connectTo,\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0connectFrom,reportHier, debugKSpace)\r\n\u00a0 LANGUAGE JAVASCRIPT AS \"traverseTree\" AT \"tree\";<\/pre>\n<p>Note, you can also create the UDF using the Query Workbench.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-13263\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/05\/image1-3-1024x386.png\" alt=\"Add UDF function in SQL++\" width=\"900\" height=\"339\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image1-3-1024x386.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image1-3-300x113.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image1-3-768x289.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image1-3-1536x579.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image1-3-20x8.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image1-3-1320x497.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/05\/image1-3.png 1954w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<h3><span style=\"font-weight: 400\">Important notes<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Couchbase 7.0 added SQL++ UDFs for JavaScript. To Couchbase 7.1 we added the ability to execute SQL++ DMLs from within the JavaScript code. There are also several Query Workbench UI enhancements for UDF management.<\/span><\/p>\n<p><b>Disclaimer <\/b><span style=\"font-weight: 400\">&#8211; Please note that the JavaScript code provided in this article is not part of the Couchase product. It is provided here only to illustrate the capabilities of SQL++ UDF using JavaScript. Users are encouraged to verify its correctness, and to make modifications to suit\u00a0 their needs.<\/span><\/p>\n<h3>Continue learning<\/h3>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li><a href=\"https:\/\/www.couchbase.com\/downloads?family=couchbase-server\" target=\"_blank\" rel=\"noopener\">Download Couchbase 7.1<\/a><\/li>\n<li><a href=\"https:\/\/www.couchbase.com\/blog\/whats-new-in-couchbase-server-7-1\/\" target=\"_blank\" rel=\"noopener\">What&#8217;s New in Couchbase 7.1<\/a><\/li>\n<li><span style=\"font-weight: 400\"><a href=\"https:\/\/github.com\/binhquocle\/Coding\/blob\/master\/udfs\/tree.js\" target=\"_blank\" rel=\"noopener\">Complete traverseTree JavaScript library (code)<\/a><\/span><\/li>\n<li><span style=\"font-weight: 400\"><a href=\"https:\/\/docs.couchbase.com\/server\/current\/eventing\/eventing-language-constructs.html\" target=\"_blank\" rel=\"noopener\">JavaScript eventing language constructs (docs)<\/a><\/span><\/li>\n<li><span style=\"font-weight: 400\"><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/userfun.html\" target=\"_blank\" rel=\"noopener\">Defining external functions in SQL++ (docs)<\/a><\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>User-defined functions (UDFs) are a feature that exist in most RDBMS. Whether it is Oracle PL\/SQL (Procedural Language for SQL), SQL Server T-SQL (Transact-SQL), PL\/pgSQL (Procedural Language\/PostgreSQL), or other variants, all these languages have the general characteristics of providing a [&hellip;]<\/p>\n","protected":false},"author":26326,"featured_media":12473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816,9327,1812],"tags":[9622,1543,8911],"ppma_author":[8919],"class_list":["post-13258","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server","category-javascript","category-n1ql-query","tag-hierarchical-data","tag-javascript","tag-udf"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Traverse Hierarchy with SQL++ User-defined functions (UDFs)<\/title>\n<meta name=\"description\" content=\"In Couchbase 7.1 you can now execute SQL++ DMLs from within the JavaScript UDF code shown in this hierarchy traversal example.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/ko\/traverse-hierarchy-user-defined-functions-in-7-1\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Traverse Hierarchy with SQL++ User-defined functions (UDFs)\" \/>\n<meta property=\"og:description\" content=\"In Couchbase 7.1 you can now execute SQL++ DMLs from within the JavaScript UDF code shown in this hierarchy traversal example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/ko\/traverse-hierarchy-user-defined-functions-in-7-1\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-26T19:05:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T06:34:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/thisisengineering-raeng-64YrPKiguAE-unsplash-1024x683.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"683\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Binh Le\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Binh Le\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/\"},\"author\":{\"name\":\"Binh Le\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/f89064928e262c71eb43bee996c48c63\"},\"headline\":\"Traverse Hierarchy with SQL++ User-defined functions (UDFs)\",\"datePublished\":\"2022-05-26T19:05:50+00:00\",\"dateModified\":\"2025-06-14T06:34:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/\"},\"wordCount\":642,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/11\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"keywords\":[\"hierarchical data\",\"javascript\",\"User Defined Function (UDF)\"],\"articleSection\":[\"Couchbase Server\",\"JavaScript\",\"SQL++ \\\/ N1QL Query\"],\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/\",\"name\":\"Traverse Hierarchy with SQL++ User-defined functions (UDFs)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/11\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"datePublished\":\"2022-05-26T19:05:50+00:00\",\"dateModified\":\"2025-06-14T06:34:35+00:00\",\"description\":\"In Couchbase 7.1 you can now execute SQL++ DMLs from within the JavaScript UDF code shown in this hierarchy traversal example.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/11\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/11\\\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg\",\"width\":7952,\"height\":5304,\"caption\":\"Creating JavaScript UDFs to traverse hierarchy in Couchbase SQL++\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/traverse-hierarchy-user-defined-functions-in-7-1\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Traverse Hierarchy with SQL++ User-defined functions (UDFs)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/admin-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/f89064928e262c71eb43bee996c48c63\",\"name\":\"Binh Le\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a939f48df6447844a8780bec264bb3be21d589336f3915fabc557075a68fa374?s=96&d=mm&r=g5b68c37e30928a9d7b2c8470b1a303b7\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a939f48df6447844a8780bec264bb3be21d589336f3915fabc557075a68fa374?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a939f48df6447844a8780bec264bb3be21d589336f3915fabc557075a68fa374?s=96&d=mm&r=g\",\"caption\":\"Binh Le\"},\"description\":\"Binh Le is a Principal Product Manager for Couchbase Query service. Prior to Couchbase, he worked at Oracle and led the product management team for Sales Cloud Analytics and CRM OnDemand. Binh holds a Bachelor's Degree in Computer Science from the University of Brighton, UK.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/author\\\/binh-le-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL++ \uc0ac\uc6a9\uc790 \uc815\uc758 \ud568\uc218(UDF)\ub97c \uc0ac\uc6a9\ud55c \ud2b8\ub798\ubc84\uc2a4 \uacc4\uce35 \uad6c\uc870","description":"\uc774\uc81c Couchbase 7.1\uc5d0\uc11c\ub294 \uc774 \uacc4\uce35 \uad6c\uc870 \ud0d0\uc0c9 \uc608\uc81c\uc5d0 \ud45c\uc2dc\ub41c JavaScript UDF \ucf54\ub4dc \ub0b4\uc5d0\uc11c SQL++ DML\uc744 \uc2e4\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/ko\/traverse-hierarchy-user-defined-functions-in-7-1\/","og_locale":"ko_KR","og_type":"article","og_title":"Traverse Hierarchy with SQL++ User-defined functions (UDFs)","og_description":"In Couchbase 7.1 you can now execute SQL++ DMLs from within the JavaScript UDF code shown in this hierarchy traversal example.","og_url":"https:\/\/www.couchbase.com\/blog\/ko\/traverse-hierarchy-user-defined-functions-in-7-1\/","og_site_name":"The Couchbase Blog","article_published_time":"2022-05-26T19:05:50+00:00","article_modified_time":"2025-06-14T06:34:35+00:00","og_image":[{"width":1024,"height":683,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/thisisengineering-raeng-64YrPKiguAE-unsplash-1024x683.jpg","type":"image\/jpeg"}],"author":"Binh Le","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Binh Le","Est. reading time":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/"},"author":{"name":"Binh Le","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f89064928e262c71eb43bee996c48c63"},"headline":"Traverse Hierarchy with SQL++ User-defined functions (UDFs)","datePublished":"2022-05-26T19:05:50+00:00","dateModified":"2025-06-14T06:34:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/"},"wordCount":642,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","keywords":["hierarchical data","javascript","User Defined Function (UDF)"],"articleSection":["Couchbase Server","JavaScript","SQL++ \/ N1QL Query"],"inLanguage":"ko-KR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/","url":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/","name":"SQL++ \uc0ac\uc6a9\uc790 \uc815\uc758 \ud568\uc218(UDF)\ub97c \uc0ac\uc6a9\ud55c \ud2b8\ub798\ubc84\uc2a4 \uacc4\uce35 \uad6c\uc870","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","datePublished":"2022-05-26T19:05:50+00:00","dateModified":"2025-06-14T06:34:35+00:00","description":"\uc774\uc81c Couchbase 7.1\uc5d0\uc11c\ub294 \uc774 \uacc4\uce35 \uad6c\uc870 \ud0d0\uc0c9 \uc608\uc81c\uc5d0 \ud45c\uc2dc\ub41c JavaScript UDF \ucf54\ub4dc \ub0b4\uc5d0\uc11c SQL++ DML\uc744 \uc2e4\ud589\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/"]}]},{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/thisisengineering-raeng-64YrPKiguAE-unsplash.jpg","width":7952,"height":5304,"caption":"Creating JavaScript UDFs to traverse hierarchy in Couchbase SQL++"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/traverse-hierarchy-user-defined-functions-in-7-1\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Traverse Hierarchy with SQL++ User-defined functions (UDFs)"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"\uce74\uc6b0\uce58\ubca0\uc774\uc2a4 \ube14\ub85c\uadf8","description":"NoSQL \ub370\uc774\ud130\ubca0\uc774\uc2a4, Couchbase","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"\uce74\uc6b0\uce58\ubca0\uc774\uc2a4 \ube14\ub85c\uadf8","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f89064928e262c71eb43bee996c48c63","name":"Binh Le","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/secure.gravatar.com\/avatar\/a939f48df6447844a8780bec264bb3be21d589336f3915fabc557075a68fa374?s=96&d=mm&r=g5b68c37e30928a9d7b2c8470b1a303b7","url":"https:\/\/secure.gravatar.com\/avatar\/a939f48df6447844a8780bec264bb3be21d589336f3915fabc557075a68fa374?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a939f48df6447844a8780bec264bb3be21d589336f3915fabc557075a68fa374?s=96&d=mm&r=g","caption":"Binh Le"},"description":"Binh Le is a Principal Product Manager for Couchbase Query service. Prior to Couchbase, he worked at Oracle and led the product management team for Sales Cloud Analytics and CRM OnDemand. Binh holds a Bachelor's Degree in Computer Science from the University of Brighton, UK.","url":"https:\/\/www.couchbase.com\/blog\/ko\/author\/binh-le-2\/"}]}},"acf":[],"authors":[{"term_id":8919,"user_id":26326,"is_guest":0,"slug":"binh-le-2","display_name":"Binh Le","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/a939f48df6447844a8780bec264bb3be21d589336f3915fabc557075a68fa374?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/posts\/13258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/users\/26326"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/comments?post=13258"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/posts\/13258\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/media\/12473"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/media?parent=13258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/categories?post=13258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/tags?post=13258"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/ko\/wp-json\/wp\/v2\/ppma_author?post=13258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}