diff --git a/pkg/sql/alter_database.go b/pkg/sql/alter_database.go index b908c746b596..2456f60b0cd8 100644 --- a/pkg/sql/alter_database.go +++ b/pkg/sql/alter_database.go @@ -152,7 +152,7 @@ func (n *alterDatabaseAddRegionNode) startExec(params runParams) error { n.n.Region.String(), n.n.Name.String(), ), - "you must add a PRIMARY REGION first using ALTER DATABASE %s SET PRIMARY REGION %s", + "you must add a PRIMARY REGION first using ALTER DATABASE %s PRIMARY REGION %s", n.n.Name.String(), n.n.Region.String(), ) @@ -308,7 +308,7 @@ func (p *planner) AlterDatabaseDropRegion( return nil, errors.WithHintf( errors.Newf("cannot drop region %q", dbDesc.RegionConfig.PrimaryRegion), "You must designate another region as the primary region using "+ - "ALTER DATABASE %s SET PRIMARY REGION or remove all other regions before "+ + "ALTER DATABASE %s PRIMARY REGION or remove all other regions before "+ "attempting to drop region %q", dbDesc.GetName(), n.Region, ) } diff --git a/pkg/sql/logictest/testdata/logic_test/multiregion b/pkg/sql/logictest/testdata/logic_test/multiregion index ba44af4601fc..2bbd0372eb7d 100644 --- a/pkg/sql/logictest/testdata/logic_test/multiregion +++ b/pkg/sql/logictest/testdata/logic_test/multiregion @@ -881,7 +881,7 @@ ALTER DATABASE non_multi_region_db DROP REGION "ca-central-1" statement ok CREATE DATABASE drop_region_db PRIMARY REGION "ca-central-1" REGIONS "ap-southeast-2", "us-east-1" -statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_region_db SET PRIMARY REGION or remove all other regions before attempting to drop region "ca-central-1" +statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_region_db PRIMARY REGION or remove all other regions before attempting to drop region "ca-central-1" ALTER DATABASE drop_region_db DROP REGION "ca-central-1" statement ok @@ -931,7 +931,7 @@ CREATE TABLE start_off_non_multi_region.public.t(a INT); ALTER DATABASE start_off_non_multi_region PRIMARY REGION "ca-central-1"; ALTER DATABASE start_off_non_multi_region ADD REGION "ap-southeast-2" -statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE start_off_non_multi_region SET PRIMARY REGION or remove all other regions before attempting to drop region "ca-central-1" +statement error pq: cannot drop region "ca-central-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE start_off_non_multi_region PRIMARY REGION or remove all other regions before attempting to drop region "ca-central-1" ALTER DATABASE start_off_non_multi_region DROP REGION "ca-central-1" statement ok @@ -1026,7 +1026,7 @@ statement ok ALTER DATABASE drop_primary_regions_db DROP REGION "ca-central-1" # Cannot drop the primary region yet, as there are other regions in the db. -statement error pq: cannot drop region "us-east-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_primary_regions_db SET PRIMARY REGION or remove all other regions before attempting to drop region "us-east-1" +statement error pq: cannot drop region "us-east-1"\nHINT: You must designate another region as the primary region using ALTER DATABASE drop_primary_regions_db PRIMARY REGION or remove all other regions before attempting to drop region "us-east-1" ALTER DATABASE drop_primary_regions_db DROP REGION "us-east-1" statement ok diff --git a/pkg/sql/parser/parse_test.go b/pkg/sql/parser/parse_test.go index e419b870b4dd..8e0b644b50fa 100644 --- a/pkg/sql/parser/parse_test.go +++ b/pkg/sql/parser/parse_test.go @@ -1830,6 +1830,9 @@ func TestParse2(t *testing.T) { `CREATE DATABASE a PRIMARY REGION = "us-west-1"`, `CREATE DATABASE a PRIMARY REGION "us-west-1"`, }, + {`ALTER DATABASE a SET PRIMARY REGION "us-west-1"`, + `ALTER DATABASE a PRIMARY REGION "us-west-1"`}, + {`CREATE TABLE a (b INT) WITH (fillfactor=100)`, `CREATE TABLE a (b INT8)`}, {`CREATE TABLE a (b INT, UNIQUE INDEX foo (b))`, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 278865832e67..4c1b01858494 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1476,7 +1476,7 @@ alter_sequence_options_stmt: // ALTER DATABASE CONVERT TO SCHEMA WITH PARENT // ALTER DATABASE ADD REGIONS // ALTER DATABASE DROP REGIONS -// ALTER DATABASE SET PRIMARY REGION +// ALTER DATABASE PRIMARY REGION // ALTER DATABASE SURVIVE // %SeeAlso: WEBDOCS/alter-database.html alter_database_stmt: @@ -1533,6 +1533,14 @@ alter_database_primary_region_stmt: PrimaryRegion: tree.Name($4), } } +| ALTER DATABASE database_name SET primary_region_clause + { + /* SKIP DOC */ + $$.val = &tree.AlterDatabasePrimaryRegion{ + Name: tree.Name($3), + PrimaryRegion: tree.Name($5), + } + } // %Help: ALTER RANGE - change the parameters of a range // %Category: DDL