diff --git a/go.mod b/go.mod index 3d0bcf0733..b84b576d85 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90 - github.com/dolthub/go-mysql-server v0.19.1-0.20250226231726-5b478d49db8b + github.com/dolthub/go-mysql-server v0.19.1-0.20250227200259-b9d44c4607d1 github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 github.com/dolthub/vitess v0.0.0-20250214225328-a0ed4612b41c github.com/fatih/color v1.13.0 diff --git a/go.sum b/go.sum index 5873ba2351..095e64a1a0 100644 --- a/go.sum +++ b/go.sum @@ -224,8 +224,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U= github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0= github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90 h1:Sni8jrP0sy/w9ZYXoff4g/ixe+7bFCZlfCqXKJSU+zM= github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA= -github.com/dolthub/go-mysql-server v0.19.1-0.20250226231726-5b478d49db8b h1:eS/NoWQad2p1WmEe8ZrX3bD0tPtCujuFguLAhiXAKLA= -github.com/dolthub/go-mysql-server v0.19.1-0.20250226231726-5b478d49db8b/go.mod h1:JTlrabhq5TJqvlL+J3NKlm0EzTHQQugUAH6yAxWi4Ww= +github.com/dolthub/go-mysql-server v0.19.1-0.20250227200259-b9d44c4607d1 h1:GhFEGULkWuOIwBM2Fv2A/OgszEDjm9CyfAQD/EEzSIA= +github.com/dolthub/go-mysql-server v0.19.1-0.20250227200259-b9d44c4607d1/go.mod h1:JTlrabhq5TJqvlL+J3NKlm0EzTHQQugUAH6yAxWi4Ww= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE= diff --git a/postgres/parser/parser/sql/sql_parser.go b/postgres/parser/parser/sql/sql_parser.go index 9a470efc7f..4846f8fd56 100644 --- a/postgres/parser/parser/sql/sql_parser.go +++ b/postgres/parser/parser/sql/sql_parser.go @@ -17,6 +17,7 @@ package sql import ( "context" "fmt" + "strings" "github.com/dolthub/doltgresql/postgres/parser/parser" "github.com/dolthub/doltgresql/server/ast" @@ -82,3 +83,7 @@ func (p *PostgresParser) ParseOneWithOptions(_ context.Context, query string, _ } return vitessAST, 0, nil } + +func (p *PostgresParser) QuoteIdentifier(identifier string) string { + return fmt.Sprintf(`"%s"`, strings.ReplaceAll(identifier, `"`, `""`)) +} diff --git a/server/analyzer/init.go b/server/analyzer/init.go index 43b0c1fd10..0282e5c011 100644 --- a/server/analyzer/init.go +++ b/server/analyzer/init.go @@ -72,7 +72,7 @@ func Init() { // The auto-commit rule writes the contents of the context, so we need to insert our finalizer before that. // We also should optimize functions last, since other rules may change the underlying expressions, potentially changing their return types. - analyzer.OnceAfterAll = insertAnalyzerRules(analyzer.OnceAfterAll, analyzer.BacktickDefaulColumnValueNamesId, false, + analyzer.OnceAfterAll = insertAnalyzerRules(analyzer.OnceAfterAll, analyzer.QuoteDefaultColumnValueNamesId, false, analyzer.Rule{Id: ruleId_OptimizeFunctions, Apply: OptimizeFunctions}, // AddDomainConstraintsToCasts needs to run after 'assignExecIndexes' rule in GMS. analyzer.Rule{Id: ruleId_AddDomainConstraintsToCasts, Apply: AddDomainConstraintsToCasts}, diff --git a/testing/go/alter_table_test.go b/testing/go/alter_table_test.go index 33bbb37af2..9c9e6224cf 100644 --- a/testing/go/alter_table_test.go +++ b/testing/go/alter_table_test.go @@ -178,6 +178,32 @@ func TestAlterTable(t *testing.T) { }, }, }, + { + Name: "Add primary key with generated column", + SetUpScript: []string{ + `CREATE TABLE t1 ( + id uuid DEFAULT public.gen_random_uuid() NOT NULL, + data jsonb, + has_data boolean GENERATED ALWAYS AS ((data IS NOT NULL)) STORED + );`, + }, + Assertions: []ScriptTestAssertion{ + { + Query: " ALTER TABLE ONLY t1 ADD CONSTRAINT pk PRIMARY KEY (id);", + SkipResultsCheck: true, // only care if it doesn't error + }, + { + Query: "insert into t1 (id, data) values (default, '{}');", + SkipResultsCheck: true, // only care if it doesn't error + }, + { + Query: "Select has_data from t1;", + Expected: []sql.Row{ + {"t"}, + }, + }, + }, + }, { Name: "Add Column", SetUpScript: []string{ diff --git a/testing/go/create_table_test.go b/testing/go/create_table_test.go index e5eb63e55d..5ff6a3f895 100755 --- a/testing/go/create_table_test.go +++ b/testing/go/create_table_test.go @@ -212,6 +212,49 @@ func TestCreateTable(t *testing.T) { }, }, }, + { + Name: "generated column with reference to another column", + SetUpScript: []string{ + `create table t1 ( + a varchar(10) primary key, + b varchar(20), + b_not_null bool generated always as ((b is not null)) stored + );`, + "insert into t1 (a, b) values ('foo', 'bar');", + "insert into t1 (a) values ('foo2');", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select * from t1 order by a;", + Expected: []sql.Row{ + {"foo", "bar", "t"}, + {"foo2", nil, "f"}, + }, + }, + }, + }, + { + Name: "generated column with reference to another column that needs quote", + Skip: true, // generated columns are not being properly quoted, this is a bug in GMS + SetUpScript: []string{ + `create table t1 ( + a varchar(10) primary key, + "b 2" varchar(20), + b_not_null bool generated always as (("b 2" is not null)) stored + );`, + `insert into t1 (a, "b 2") values ('foo', 'bar');`, + "insert into t1 (a) values ('foo2');", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select * from t1 order by a;", + Expected: []sql.Row{ + {"foo", "bar", "t"}, + {"foo2", nil, "f"}, + }, + }, + }, + }, { Name: "create table with default value", SetUpScript: []string{