{"record":{"id":"b8d5aa6bc29c9e4d","repo":"t8y2/dbx","slug":"materialized-view-q-q-returned-an-empty-source-d","errorCode":null,"errorMessage":"materialized view %q.%q returned an empty source definition","messagePattern":"materialized view %q\\.%q returned an empty source definition","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":2187,"sourceCode":"\t}\n\n\tsource, err := querySource(function)\n\tif err == nil {\n\t\treturn source, nil\n\t}\n\tif function == \"sys_get_viewdef\" {\n\t\tif isUndefinedFunction(err, function) {\n\t\t\ts.usePgViewDefinition = true\n\t\t} else if !errors.Is(err, sql.ErrNoRows) {\n\t\t\treturn \"\", err\n\t\t}\n\t\tsource, err = querySource(\"pg_get_viewdef\")\n\t\tif err == nil {\n\t\t\treturn source, nil\n\t\t}\n\t}\n\tif errors.Is(err, sql.ErrNoRows) {\n\t\treturn \"\", fmt.Errorf(\"materialized view %q.%q returned an empty source definition\", schema, name)\n\t}\n\treturn \"\", err\n}\n\nfunc (s *server) getTableDDL(schema, table string) (string, error) {\n\teffective, err := s.effectiveSchema(schema)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tcolumns, err := s.getColumns(effective, table)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\ttableComment, _ := s.getTableComment(effective, table)\n\tddl := s.renderTableDDL(effective, table, columns, tableComment)\n\tddl, err = s.appendTableIndexDDL(effective, table, ddl)\n\tif err != nil {\n\t\treturn \"\", err","sourceCodeStart":2169,"sourceCodeEnd":2205,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L2169-L2205","documentation":"The driver fetched the source of a materialized view via pg_get_viewdef and got back sql.ErrNoRows (an empty definition). Since a materialized view must have a definition, the driver converts this into a descriptive error naming schema and view.","triggerScenarios":"Calling getMaterializedViewDDL/getMaterializedViewSource for a matview whose pg_get_viewdef query returns no row — typically because the view does not actually exist in the effective schema, or the definition is empty/unreadable by the current user.","commonSituations":"Typo in schema or view name combined with a non-strict search_path; insufficient privileges to see the view definition; querying a view that was dropped concurrently; cross-database references the def-query cannot resolve.","solutions":["Verify the schema and materialized view name (check search_path / case sensitivity)","Confirm the view exists: SELECT 1 FROM pg_matviews WHERE schemaname=... AND matviewname=...","Check the current user has privileges on the view (or query as superuser)","Run the underlying definition query manually to see why it returns no rows"],"exampleFix":"// before\nsrc, err := server.GetMaterializedViewDDL(ctx, \"pubic\", \"mv_sales\") // typo schema\n// after\nsrc, err := server.GetMaterializedViewDDL(ctx, \"public\", \"mv_sales\")","handlingStrategy":"validation","validationCode":"// Go: confirm the matview exists and is visible before fetching DDL\nvar exists bool\ndb.QueryRow(`SELECT EXISTS (SELECT 1 FROM pg_matviews WHERE schemaname=$1 AND matviewname=$2)`, schema, name).Scan(&exists)\nif !exists {\n    return fmt.Errorf(\"materialized view %s.%s not found\", schema, name)\n}","typeGuard":null,"tryCatchPattern":"src, err := server.GetMaterializedViewDDL(ctx, schema, name)\nif err != nil {\n    if strings.Contains(err.Error(), \"empty source definition\") {\n        return fmt.Errorf(\"check name/privileges for matview %s.%s: %w\", schema, name, err)\n    }\n    return err\n}","preventionTips":["Use fully-qualified schema.view names; avoid relying on search_path","Grant the introspection user privileges on the matview","Verify existence in pg_matviews before DDL operations"],"tags":["kingbase","materialized-view","metadata","ddl","go"],"backgroundTag":"empty-definition-returned","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}