From d09ea03b46b72b9481f0d848ce31725ad14252ef Mon Sep 17 00:00:00 2001 From: Oliver Tan Date: Wed, 3 Nov 2021 20:32:55 +1100 Subject: [PATCH] support more extensions --- .../sql/bnf/create_extension_stmt.bnf | 1 + docs/generated/sql/bnf/stmt_block.bnf | 1 + pkg/sql/create_extension.go | 3 +-- pkg/sql/parser/sql.y | 4 +++ pkg/sql/pg_catalog.go | 25 ++++++++++++++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/docs/generated/sql/bnf/create_extension_stmt.bnf b/docs/generated/sql/bnf/create_extension_stmt.bnf index 18affcc235e5..9b42843ecc31 100644 --- a/docs/generated/sql/bnf/create_extension_stmt.bnf +++ b/docs/generated/sql/bnf/create_extension_stmt.bnf @@ -1,3 +1,4 @@ create_extension_stmt ::= 'CREATE' 'EXTENSION' 'IF' 'NOT' 'EXISTS' name + | 'CREATE' 'EXTENSION' 'IF' 'NOT' 'EXISTS' name 'SCHEMA' name | 'CREATE' 'EXTENSION' name diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index da806b77f112..19ac445036de 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -472,6 +472,7 @@ create_replication_stream_stmt ::= create_extension_stmt ::= 'CREATE' 'EXTENSION' 'IF' 'NOT' 'EXISTS' name + | 'CREATE' 'EXTENSION' 'IF' 'NOT' 'EXISTS' name 'SCHEMA' name | 'CREATE' 'EXTENSION' name opt_with_clause ::= diff --git a/pkg/sql/create_extension.go b/pkg/sql/create_extension.go index e2a821156e50..3c77b4559d11 100644 --- a/pkg/sql/create_extension.go +++ b/pkg/sql/create_extension.go @@ -43,7 +43,7 @@ func (n *createExtensionNode) unimplementedExtensionError(issue int) error { func (n *createExtensionNode) startExec(params runParams) error { switch n.CreateExtension.Name { - case "postgis": + case "postgis", "pgcrypto": telemetry.Inc(sqltelemetry.CreateExtensionCounter(n.CreateExtension.Name)) return nil case "postgis_raster", @@ -85,7 +85,6 @@ func (n *createExtensionNode) startExec(params runParams) error { "pageinspect", "passwordcheck", "pg_buffercache", - "pgcrypto", "pg_freespacemap", "pg_prewarm", "pgrowlocks", diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 844f79fba8ac..f64a779e56f2 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -3478,6 +3478,10 @@ create_extension_stmt: { $$.val = &tree.CreateExtension{IfNotExists: true, Name: $6} } +| CREATE EXTENSION IF NOT EXISTS name SCHEMA name + { + $$.val = &tree.CreateExtension{IfNotExists: true, Name: $6} + } | CREATE EXTENSION name { $$.val = &tree.CreateExtension{Name: $3} } diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 85c925d7a312..c9e501f6da37 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -569,7 +569,30 @@ var pgCatalogAvailableExtensionsTable = virtualSchemaTable{ https://www.postgresql.org/docs/9.6/view-pg-available-extensions.html`, schema: vtable.PGCatalogAvailableExtensions, populate: func(ctx context.Context, p *planner, _ catalog.DatabaseDescriptor, addRow func(...tree.Datum) error) error { - // We support no extensions. + // We support few extensions. + for _, ext := range []struct { + name string + defaultVersion string + installedVersion string + comment string + }{ + {name: "postgis", defaultVersion: "3.0.1", installedVersion: "3.0.1", comment: "PostGIS geometry and geography spatial types and functions"}, + {name: "uuid-ossp", defaultVersion: "1.1", comment: "generate universally unique identifiers (UUIDs)"}, + {name: "pgcrypto", defaultVersion: "1.3", comment: "cryptographic functions"}, + } { + var installedVersion tree.Datum = tree.DNull + if ext.installedVersion != "" { + installedVersion = tree.NewDString(ext.installedVersion) + } + if err := addRow( + tree.NewDString(ext.name), + tree.NewDString(ext.defaultVersion), + installedVersion, + tree.NewDString(ext.comment), + ); err != nil { + return err + } + } return nil }, unimplemented: true,