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

Panic on converting regclass to string #1142

Open
zachmu opened this issue Jan 22, 2025 · 0 comments
Open

Panic on converting regclass to string #1142

zachmu opened this issue Jan 22, 2025 · 0 comments

Comments

@zachmu
Copy link
Member

zachmu commented Jan 22, 2025

Running this query with the DEBUG_ANALYZER=true environment:

SELECT relname FROM pg_catalog.pg_class WHERE oid = 'testing'::regclass;

Yields a panic. The root cause is that the regclass cast expression is having String() called on it, which eventually calls this:

func (t *DoltgresType) FormatValue(val any) (string, error) {
	if val == nil {
		return "", nil
	}
	// TODO: need valid sql.Context
	return t.IoOutput(nil, val)
}

Which ultimately calls:

// regclassout represents the PostgreSQL function of regclass type IO output.
var regclassout = framework.Function1{
	Name:       "regclassout",
	Return:     pgtypes.Cstring,
	Parameters: [1]*pgtypes.DoltgresType{pgtypes.Regclass},
	Strict:     true,
	Callable: func(ctx *sql.Context, _ [2]*pgtypes.DoltgresType, val any) (any, error) {
		// Find all the schemas on the search path. If a schema is on the search path, then it is not included in the
		// output of relation name. If the relation's schema is not on the search path, then it is explicitly included.
		schemasMap, err := settings.GetCurrentSchemasAsMap(ctx)

This is easy to trigger with the debug env vars, but will also happen when running DESCRIBE statements, and probably in other circumstances (column default values, really any time we need to convert a regclass to a string).

Not sure the best fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant