{"record":{"id":"a48dd8e9cb2b0819","repo":"t8y2/dbx","slug":"trigger-q-is-ambiguous-in-schema-q-relation-nam","errorCode":null,"errorMessage":"trigger %q is ambiguous in schema %q; relation_name is required","messagePattern":"trigger %q is ambiguous in schema %q; relation_name is required","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":2137,"sourceCode":"\t\t\terr = querySource(function)\n\t\t\tif err != nil && function == \"sys_get_functiondef\" && isUndefinedFunction(err, function) {\n\t\t\t\ts.usePgFunctionDefinition = true\n\t\t\t\tfunction = \"pg_get_functiondef\"\n\t\t\t\terr = querySource(function)\n\t\t\t}\n\t\t\tif err != nil && !s.mode.postgresCatalog && function == \"pg_get_functiondef\" && isUndefinedFunction(err, function) {\n\t\t\t\ts.useLegacyRoutineDefinition = true\n\t\t\t\terr = queryLegacySource()\n\t\t\t}\n\t\t}\n\t} else if kind == \"TRIGGER\" {\n\t\tdefinitions, triggerErr := s.listTriggerDefinitionsFor(effective, relationName, name)\n\t\tif triggerErr != nil {\n\t\t\terr = triggerErr\n\t\t} else if len(definitions) == 1 {\n\t\t\tsource = definitions[0]\n\t\t} else if len(definitions) > 1 {\n\t\t\terr = fmt.Errorf(\"trigger %q is ambiguous in schema %q; relation_name is required\", name, effective)\n\t\t} else {\n\t\t\terr = sql.ErrNoRows\n\t\t}\n\t}\n\tif err != nil && err != sql.ErrNoRows {\n\t\treturn nil, err\n\t}\n\tresult := map[string]any{\"name\": name, \"object_type\": objectType, \"schema\": effective, \"source\": source}\n\tif kind == \"TRIGGER\" {\n\t\tresult[\"editable\"] = false\n\t}\n\treturn result, nil\n}\n\nfunc (s *server) getMaterializedViewSource(schema, name string) (string, error) {\n\tcatalog, prefix, function := \"sys_catalog\", \"sys\", \"sys_get_viewdef\"\n\tif s.mode.postgresCatalog {\n\t\tcatalog, prefix, function = \"pg_catalog\", \"pg\", \"pg_get_viewdef\"","sourceCodeStart":2119,"sourceCodeEnd":2155,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L2119-L2155","documentation":"Looking up a single trigger by name within a schema found more than one trigger with that name on different relations. Because the driver cannot disambiguate, it returns this error telling you to provide relation_name. (The DECLARED-AS/USED-AT lines referencing agent_compare.py are unrelated index noise; the error lives in the Kingbase metadata server.)","triggerScenarios":"Calling getTrigger/getTriggerDDL (or similar) with schema and trigger name but without relation_name, when two or more tables in the same schema each define a trigger of the same name.","commonSituations":"Schemas where naming conventions reuse trigger names (e.g. 'audit_trigger' on many tables); migrations that cloned tables including their triggers; tooling that omits the optional relation_name parameter.","solutions":["Pass relation_name identifying the table that owns the trigger","List triggers for the schema to see the duplicates and pick the correct relation","Rename duplicate triggers so names are unique per schema","If the driver supports it, filter by relation in the query instead of only by name"],"exampleFix":"// before\ndef, err := server.GetTrigger(ctx, \"public\", \"audit_trigger\", \"\")\n// after: supply the owning relation\ndef, err := server.GetTrigger(ctx, \"public\", \"audit_trigger\", \"orders\")","handlingStrategy":"validation","validationCode":"// Go: ensure trigger name is unique in schema before lookup\nvar n int\ndb.QueryRow(`SELECT count(*) FROM pg_trigger t JOIN pg_class c ON c.oid=t.tgrelid JOIN pg_namespace n ON n.oid=c.relnamespace WHERE t.tgname=$1 AND n.nspname=$2`, trigName, schema).Scan(&n)\nif n > 1 {\n    return fmt.Errorf(\"trigger %s is ambiguous in %s; pass relation_name\", trigName, schema)\n}","typeGuard":null,"tryCatchPattern":"def, err := server.GetTrigger(ctx, schema, name, relation)\nif err != nil && strings.Contains(err.Error(), \"is ambiguous\") {\n    // list triggers and pick the one for the intended relation\n    return listAndPickTrigger(server, schema, name)\n}","preventionTips":["Always pass relation_name when fetching triggers","Enforce unique trigger names per schema in migration conventions","Duplicate-table copies: rename cloned triggers immediately"],"tags":["kingbase","trigger","ambiguity","metadata","go"],"backgroundTag":"ambiguous-object-name","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}