Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-12092

Add SQL++ function to extract DDL statements

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Minor
    • Morpheus
    • Morpheus
    • query
    • None
    • 0

    Description

      To https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/metafun.html add:

      EXTRACTDDL(filter [,options])

      Description

      Extracts DDL statements from the matching buckets in accordance with the options provided, returning an array of strings containing the statements.

      The user must have query_system_catalog authority and authority to access the individual buckets in order to extract the DDL.

      Arguments

      filter

      String value LIKE pattern for matching against bucket names.  An empty string matches all names.

      options

      An optional object value containing the field:

      • flags
        • A numeric representation of the flags or an array of string flag values.
        • flag values
          • bucket - include CREATE BUCKET statements
          • scope - include CREATE SCOPE statements
          • collection - include CREATE COLLECTION statements
          • index - include CREATE INDEX statements
          • sequence - include CREATE SEQUENCE statements

      When options is not specified (or if it doesn't include the flags field) then all statements are included in the output.

      Example

      SELECT extractddl("travel-sample",{"flags":["index"]});
      ...
          "results": [
          {
              "$1": [
                  "CREATE INDEX `def_airportname` ON `travel-sample`(`airportname`) ;",
                  "CREATE INDEX `def_city` ON `travel-sample`(`city`) ;",
                  "CREATE INDEX `def_faa` ON `travel-sample`(`faa`) ;",
                  "CREATE INDEX `def_icao` ON `travel-sample`(`icao`) ;",
                  "CREATE INDEX `def_inventory_airline_primary` ON `travel-sample`.`inventory`.`airline`;",
                  "CREATE INDEX `def_inventory_airport_airportname` ON `travel-sample`.`inventory`.`airport`(`airportname`) ;",
                  "CREATE INDEX `def_inventory_airport_city` ON `travel-sample`.`inventory`.`airport`(`city`) ;",
                  "CREATE INDEX `def_inventory_airport_faa` ON `travel-sample`.`inventory`.`airport`(`faa`) ;",
                  "CREATE INDEX `def_inventory_airport_primary` ON `travel-sample`.`inventory`.`airport`;",
                  "CREATE INDEX `def_inventory_hotel_city` ON `travel-sample`.`inventory`.`hotel`(`city`) ;",
                  "CREATE INDEX `def_inventory_hotel_primary` ON `travel-sample`.`inventory`.`hotel`;",
                  "CREATE INDEX `def_inventory_landmark_city` ON `travel-sample`.`inventory`.`landmark`(`city`) ;",
                  "CREATE INDEX `def_inventory_landmark_primary` ON `travel-sample`.`inventory`.`landmark`;",
                  "CREATE INDEX `def_inventory_route_primary` ON `travel-sample`.`inventory`.`route`;",
                  "CREATE INDEX `def_inventory_route_route_src_dst_day` ON `travel-sample`.`inventory`.`route`(`sourceairport`,`destinationairport`,(distinct (array (`v`.`day`) for `v` in `schedule` end))) ;",
                  "CREATE INDEX `def_inventory_route_schedule_utc` ON `travel-sample`.`inventory`.`route`(array (`s`.`utc`) for `s` in `schedule` end) ;",
                  "CREATE INDEX `def_inventory_route_sourceairport` ON `travel-sample`.`inventory`.`route`(`sourceairport`) ;",
                  "CREATE INDEX `def_name_type` ON `travel-sample`(`name`)  WHERE (`_type` = 'User');",
                  "CREATE INDEX `def_primary` ON `travel-sample`;",
                  "CREATE INDEX `def_route_src_dst_day` ON `travel-sample`(`sourceairport`,`destinationairport`,(distinct (array (`v`.`day`) for `v` in `schedule` end)))  WHERE (`type` = 'route');",
                  "CREATE INDEX `def_schedule_utc` ON `travel-sample`(array (`s`.`utc`) for `s` in `schedule` end) ;",
                  "CREATE INDEX `def_sourceairport` ON `travel-sample`(`sourceairport`) ;",
                  "CREATE INDEX `def_type` ON `travel-sample`(`type`) ;"
              ]
          }
      ...
      

       

       

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              simon.dew Simon Dew
              Donald.haggart Donald Haggart
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty