Skip to content

Commit

Permalink
support more extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
otan committed Nov 3, 2021
1 parent 084f8a0 commit d09ea03
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/create_extension_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
create_extension_stmt ::=
'CREATE' 'EXTENSION' 'IF' 'NOT' 'EXISTS' name
| 'CREATE' 'EXTENSION' 'IF' 'NOT' 'EXISTS' name 'SCHEMA' name
| 'CREATE' 'EXTENSION' name
1 change: 1 addition & 0 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ::=
Expand Down
3 changes: 1 addition & 2 deletions pkg/sql/create_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -85,7 +85,6 @@ func (n *createExtensionNode) startExec(params runParams) error {
"pageinspect",
"passwordcheck",
"pg_buffercache",
"pgcrypto",
"pg_freespacemap",
"pg_prewarm",
"pgrowlocks",
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
25 changes: 24 additions & 1 deletion pkg/sql/pg_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d09ea03

Please sign in to comment.