Skip to content

Commit d6db098

Browse files
[DOC-13700] Update EXTRACTDDL() to add new flags 8.0.1 (#471)
1 parent 9368f40 commit d6db098

File tree

1 file changed

+123
-7
lines changed

1 file changed

+123
-7
lines changed

modules/n1ql/pages/n1ql-language-reference/metafun.adoc

Lines changed: 123 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ SELECT `Flavor` FROM EVALUATE("INFER `travel-sample`")[0] inf;
428428
=== Description
429429

430430
This function extracts Data Definition Language (DDL) statements of buckets and returns them as an array of strings.
431-
It retrieves definitions for buckets, scopes, collections, indexes, and sequences.
431+
It retrieves definitions for buckets, scopes, collections, indexes, sequences, functions, and prepared statements.
432+
432433
You can use these definitions for purposes such as replication, backup, or auditing.
433434

434435
The function supports the following statements:
@@ -438,6 +439,8 @@ The function supports the following statements:
438439
* CREATE COLLECTION
439440
* CREATE INDEX
440441
* CREATE SEQUENCE
442+
* CREATE OR REPLACE FUNCTION [.status]#Couchbase Server 8.0.1#
443+
* PREPARE [.status]#Couchbase Server 8.0.1#
441444

442445
NOTE: To execute this function, you must have the `query_system_catalog` role.
443446
Also, to extract DDLs from a specific bucket, you need necessary permissions on that bucket.
@@ -463,12 +466,12 @@ If you omit this argument, the output includes all supported DDL statements.
463466
__optional__
464467
| Specifies the types of DDL statements to extract.
465468

466-
Accepts either a numeric value or an array of strings, but not both.
469+
Accepts either a number or an array of strings, but not both.
467470

468-
[options="header", cols="1a,1a,1a"]
471+
[options="header", cols="3a,2a,1a"]
469472
!===
470473

471-
! Statement ! String Value ! Numeric Value
474+
! Statement ! String ! Number
472475

473476
! CREATE BUCKET
474477
! `"bucket"`
@@ -489,6 +492,17 @@ Accepts either a numeric value or an array of strings, but not both.
489492
! CREATE SEQUENCE
490493
! `"sequence"`
491494
! `16`
495+
496+
! CREATE OR REPLACE FUNCTION +
497+
[.status]#Couchbase Server 8.0.1#
498+
499+
! `"function"`
500+
! `32`
501+
502+
! PREPARE +
503+
[.status]#Couchbase Server 8.0.1#
504+
! `"prepared"`
505+
! `64`
492506
!===
493507

494508
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.
@@ -505,7 +519,7 @@ An array of strings, with each string containing a DDL statement.
505519
=== Examples
506520

507521
[[extract-ddl-ex1,EXTRACTDDL() Example 1]]
508-
.Using a string flag to extract CREATE INDEX statements from the `travel-sample` bucket
522+
.Extract CREATE INDEX statements from the `travel-sample` bucket using a string flag
509523
====
510524
.Query
511525
[source,sqlpp]
@@ -531,7 +545,7 @@ SELECT extractddl("travel-sample",{"flags":["index"]});
531545
====
532546

533547
[[extract-ddl-ex2,EXTRACTDDL() Example 2]]
534-
.Using a numeric flag to extract CREATE INDEX statements from the `travel-sample` bucket
548+
.Extract CREATE INDEX statements from the `travel-sample` bucket using a numeric flag
535549
====
536550
.Query
537551
[source,sqlpp]
@@ -557,7 +571,7 @@ SELECT extractddl("travel-sample", {"flags":8});
557571
====
558572

559573
[[extract-ddl-ex3,EXTRACTDDL() Example 3]]
560-
.Using a combined numeric flag to extract CREATE BUCKET and CREATE SCOPE statements from the `travel-sample` bucket
574+
.Extract CREATE BUCKET and CREATE SCOPE statements from the `travel-sample` bucket using a numeric flag
561575
====
562576
.Query
563577
[source,sqlpp]
@@ -591,6 +605,108 @@ In this query, the value `3` represents the sum of the flags for bucket (`1`) an
591605
----
592606
====
593607

608+
[[extract-ddl-ex4,EXTRACTDDL() Example 4]]
609+
.Extract CREATE FUNCTION and PREPARE statements from the `travel-sample` bucket
610+
====
611+
.Query
612+
[source,sqlpp]
613+
----
614+
SELECT extractddl("travel-sample",{"flags":["function","prepared"]});
615+
----
616+
.Results
617+
[source,json]
618+
----
619+
[
620+
{
621+
"$1": [
622+
"CREATE OR REPLACE FUNCTION `celsius`(...)
623+
LANGUAGE INLINE AS (args[0] - 32) * 5/9;",
624+
"PREPARE SELECT * FROM route\n
625+
WHERE airline = \"FL\";",
626+
"PREPARE NameParam AS\nSELECT * FROM hotel\n
627+
WHERE city=$city AND country=$country;"
628+
]
629+
}
630+
]
631+
----
632+
====
633+
634+
[[extract-ddl-ex5,EXTRACTDDL() Example 5]]
635+
.Extract all supported DDL statements from the `travel-sample` bucket
636+
====
637+
.Query
638+
[source,sqlpp]
639+
----
640+
SELECT extractddl("travel-sample");
641+
----
642+
.Results
643+
[source,json]
644+
----
645+
[
646+
{
647+
"$1": [
648+
"CREATE OR REPLACE FUNCTION `celsius`(...)
649+
LANGUAGE INLINE AS (args[0] - 32) * 5/9;",
650+
"CREATE BUCKET `travel-sample`
651+
WITH {'evictionPolicy':'fullEviction',
652+
'numVBuckets':128,
653+
'ramQuota':200,
654+
'replicaNumber':0,
655+
'storageBackend':'magma'
656+
};",
657+
"CREATE SCOPE `travel-sample`.`inventory`;",
658+
"CREATE COLLECTION `travel-sample`.`inventory`.`airline;",
659+
"CREATE COLLECTION `travel-sample`.`inventory`.`airport;",
660+
"CREATE COLLECTION `travel-sample`.`inventory`.`hotel;",
661+
"CREATE COLLECTION `travel-sample`.`inventory`.`landmark;",
662+
"CREATE COLLECTION `travel-sample`.`inventory`.`route;",
663+
"CREATE SCOPE `travel-sample`.`tenant_agent_00`;",
664+
...
665+
"CREATE INDEX `def_airportname`
666+
ON `travel-sample`(`airportname`) ;",
667+
"CREATE INDEX `def_city`
668+
ON `travel-sample`(`city`) ;",
669+
...
670+
]
671+
}
672+
]
673+
----
674+
====
675+
676+
[[extract-ddl-ex6,EXTRACTDDL() Example 6]]
677+
.Extract DDL statements from all buckets
678+
====
679+
.Query
680+
[source,sqlpp]
681+
----
682+
SELECT extractddl("",{"flags":["bucket","scope"]});
683+
----
684+
.Results
685+
[source,json]
686+
----
687+
[
688+
{
689+
"$1": [
690+
"CREATE BUCKET `travel-sample`
691+
WITH {'evictionPolicy':'fullEviction',
692+
'numVBuckets':128,
693+
'ramQuota':200,
694+
'replicaNumber':0,
695+
'storageBackend':'magma'
696+
};",
697+
"CREATE SCOPE `travel-sample`.`inventory`;",
698+
"CREATE SCOPE `travel-sample`.`tenant_agent_00`;",
699+
"CREATE SCOPE `travel-sample`.`tenant_agent_01`;",
700+
"CREATE SCOPE `travel-sample`.`tenant_agent_02`;",
701+
"CREATE SCOPE `travel-sample`.`tenant_agent_03`;",
702+
"CREATE SCOPE `travel-sample`.`tenant_agent_04`;"
703+
]
704+
}
705+
]
706+
----
707+
====
708+
709+
594710

595711
[[finderr,FINDERR()]]
596712
== FINDERR(`expression`)

0 commit comments

Comments
 (0)