Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column default value expression error #850

Closed
fulghum opened this issue Oct 14, 2024 · 1 comment · Fixed by #879
Closed

Column default value expression error #850

fulghum opened this issue Oct 14, 2024 · 1 comment · Fixed by #879
Labels
bug Something isn't working customer issue

Comments

@fulghum
Copy link
Contributor

fulghum commented Oct 14, 2024

After adding a column default value expression, Doltgres is unable to insert data into a table or add a primary key to the table because it can't analyze the column default value expression correctly.

CREATE TABLE public."Testing_Table_1" (
	"String_Data" text,
	id integer NOT NULL
);

CREATE SEQUENCE public."Testing_Table_1_id_seq"
      AS integer
      START WITH 1
      INCREMENT BY 1
      NO MINVALUE
      NO MAXVALUE
      CACHE 1;

ALTER TABLE ONLY public."Testing_Table_1" ALTER COLUMN id SET DEFAULT nextval('public."Testing_Table_1_id_seq"'::regclass);

insert into "Testing_Table_1" ("String_Data") VALUES ('bar');

Doltgres (i.e. GMS) seems to get confused about the value passed into the nextval function. It treats 'public."Testing_Table_1_id_seq"' as a column identify, and then errors out when it doesn't know about a table named "public". GMS should not assume this is a column identity.

Here's the stack trace from the error:

unable to prepare query: table not found: public

github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).buildScalar
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/scalar.go:125
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).buildScalar
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/scalar.go:262
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).selectExprToExpression
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/project.go:178
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).buildScalar
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/scalar.go:158
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).buildScalar
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/scalar.go:195
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).convertDefaultExpression
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/ddl.go:1547
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).resolveColumnDefaultExpression
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/ddl.go:1540
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).resolveSchemaDefaults
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/ddl.go:1461
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).buildInsert
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/dml.go:86
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).buildSubquery
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/builder.go:234
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).build
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/builder.go:198
github.com/dolthub/go-mysql-server/sql/planbuilder.(*Builder).BindOnly
	/Users/jason/Projects/secondary-go-mysql-server/sql/planbuilder/parse.go:101
github.com/dolthub/go-mysql-server.(*Engine).PrepareParsedQuery
	/Users/jason/Projects/secondary-go-mysql-server/engine.go:241
github.com/dolthub/doltgresql/server.(*DoltgresHandler).ComPrepareParsed
	/Users/jason/Projects/secondary-doltgres/server/doltgres_handler.go:121
github.com/dolthub/doltgresql/server.(*ConnectionHandler).handleParse
	/Users/jason/Projects/secondary-doltgres/server/connection_handler.go:465
github.com/dolthub/doltgresql/server.(*ConnectionHandler).handleMessage
	/Users/jason/Projects/secondary-doltgres/server/connection_handler.go:363
github.com/dolthub/doltgresql/server.(*ConnectionHandler).receiveMessage
	/Users/jason/Projects/secondary-doltgres/server/connection_handler.go:333
github.com/dolthub/doltgresql/server.(*ConnectionHandler).HandleConnection
	/Users/jason/Projects/secondary-doltgres/server/connection_handler.go:157

Originally reported in #843

@fulghum fulghum added bug Something isn't working customer issue labels Oct 14, 2024
@fulghum
Copy link
Contributor Author

fulghum commented Oct 14, 2024

This only seems to happen with the value is cast to regclass. Without the ::regclass suffix, the queries above work correctly.

This seems to be happening in the nodeSelectExpr function:

return &vitess.AliasedExpr{

We're returning an AliasedExpr where the column default value is aliased as a column identifier, but that doesn't seem correct for a column default value expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working customer issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant