Skip to content

Commit 5952de0

Browse files
committed
Merge branch 'release/8.0' into release/8.1
2 parents a704ba1 + 3a85e70 commit 5952de0

8 files changed

Lines changed: 1332 additions & 76 deletions

File tree

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

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

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

432433
The function supports the following statements:
@@ -436,6 +437,8 @@ The function supports the following statements:
436437
* CREATE COLLECTION
437438
* CREATE INDEX
438439
* CREATE SEQUENCE
440+
* CREATE OR REPLACE FUNCTION [.status]#Couchbase Server 8.0.1#
441+
* PREPARE [.status]#Couchbase Server 8.0.1#
439442

440443
NOTE: To execute this function, you must have the `query_system_catalog` role.
441444
Also, to extract DDLs from a specific bucket, you need necessary permissions on that bucket.
@@ -461,12 +464,12 @@ If you omit this argument, the output includes all supported DDL statements.
461464
__optional__
462465
| Specifies the types of DDL statements to extract.
463466

464-
Accepts either a numeric value or an array of strings, but not both.
467+
Accepts either a number or an array of strings, but not both.
465468

466-
[options="header", cols="1a,1a,1a"]
469+
[options="header", cols="3a,2a,1a"]
467470
!===
468471

469-
! Statement ! String Value ! Numeric Value
472+
! Statement ! String ! Number
470473

471474
! CREATE BUCKET
472475
! `"bucket"`
@@ -487,6 +490,17 @@ Accepts either a numeric value or an array of strings, but not both.
487490
! CREATE SEQUENCE
488491
! `"sequence"`
489492
! `16`
493+
494+
! CREATE OR REPLACE FUNCTION +
495+
[.status]#Couchbase Server 8.0.1#
496+
497+
! `"function"`
498+
! `32`
499+
500+
! PREPARE +
501+
[.status]#Couchbase Server 8.0.1#
502+
! `"prepared"`
503+
! `64`
490504
!===
491505

492506
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.
@@ -503,7 +517,7 @@ An array of strings, with each string containing a DDL statement.
503517
=== Examples
504518

505519
[[extract-ddl-ex1,EXTRACTDDL() Example 1]]
506-
.Using a string flag to extract CREATE INDEX statements from the `travel-sample` bucket
520+
.Extract CREATE INDEX statements from the `travel-sample` bucket using a string flag
507521
====
508522
.Query
509523
[source,sqlpp]
@@ -529,7 +543,7 @@ SELECT extractddl("travel-sample",{"flags":["index"]});
529543
====
530544

531545
[[extract-ddl-ex2,EXTRACTDDL() Example 2]]
532-
.Using a numeric flag to extract CREATE INDEX statements from the `travel-sample` bucket
546+
.Extract CREATE INDEX statements from the `travel-sample` bucket using a numeric flag
533547
====
534548
.Query
535549
[source,sqlpp]
@@ -555,7 +569,7 @@ SELECT extractddl("travel-sample", {"flags":8});
555569
====
556570

557571
[[extract-ddl-ex3,EXTRACTDDL() Example 3]]
558-
.Using a combined numeric flag to extract CREATE BUCKET and CREATE SCOPE statements from the `travel-sample` bucket
572+
.Extract CREATE BUCKET and CREATE SCOPE statements from the `travel-sample` bucket using a numeric flag
559573
====
560574
.Query
561575
[source,sqlpp]
@@ -589,6 +603,108 @@ In this query, the value `3` represents the sum of the flags for bucket (`1`) an
589603
----
590604
====
591605

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

593709
[[finderr,FINDERR()]]
594710
== FINDERR(`expression`)

0 commit comments

Comments
 (0)