Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion modules/n1ql/pages/n1ql-language-reference/metafun.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ SELECT `Flavor` FROM EVALUATE("INFER `travel-sample`")[0] inf;
=== Description

This function extracts Data Definition Language (DDL) statements of buckets and returns them as an array of strings.
It retrieves definitions for buckets, scopes, collections, indexes, and sequences.
It retrieves definitions for buckets, scopes, collections, indexes, sequences, functions, and prepared statements.

You can use these definitions for purposes such as replication, backup, or auditing.

The function supports the following statements:
Expand All @@ -438,6 +439,8 @@ The function supports the following statements:
* CREATE COLLECTION
* CREATE INDEX
* CREATE SEQUENCE
* CREATE FUNCTION [.status]#Couchbase Server 8.0.1#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency

Suggested change
* CREATE FUNCTION [.status]#Couchbase Server 8.0.1#
* CREATE OR REPLACE FUNCTION [.status]#Couchbase Server 8.0.1#

* PREPARE [.status]#Couchbase Server 8.0.1#

NOTE: To execute this function, you must have the `query_system_catalog` role.
Also, to extract DDLs from a specific bucket, you need necessary permissions on that bucket.
Expand Down Expand Up @@ -489,6 +492,17 @@ Accepts either a numeric value or an array of strings, but not both.
! CREATE SEQUENCE
! `"sequence"`
! `16`

! CREATE OR REPLACE FUNCTION +
[.status]#Couchbase Server 8.0.1#

! `"function"`
! `32`

! PREPARE +
[.status]#Couchbase Server 8.0.1#
! `"prepared"`
! `64`
!===

To extract multiple statement types, specify an array of their string values or a single numeric value that represents the sum of their respective numeric values.
Expand Down Expand Up @@ -591,6 +605,32 @@ In this query, the value `3` represents the sum of the flags for bucket (`1`) an
----
====

[[finderr-ex4,EXTRACTDDL() Example 4]]
.Extracting CREATE FUNCTION and PREPARE statements from the `travel-sample` bucket
====
.Query
[source,sqlpp]
----
SELECT extractddl("travel-sample",{"flags":["function","prepared"]});
----
.Results
[source,json]
----
[
{
"$1": [
"CREATE OR REPLACE FUNCTION `celsius`(...)
LANGUAGE INLINE AS (args[0] - 32) * 5/9;",
"PREPARE SELECT * FROM route\n
WHERE airline = \"FL\";",
"PREPARE NameParam AS\nSELECT * FROM hotel\n
WHERE city=$city AND country=$country;"
]
}
]
----
====


[[finderr,FINDERR()]]
== FINDERR(`expression`)
Expand Down
Loading