t8y2/dbx · error

trigger %q is ambiguous in schema %q; relation_name is requi

Error message

trigger %q is ambiguous in schema %q; relation_name is required

What it means

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.)

Source

Thrown at agents/drivers/kingbase-go/kingbase_metadata.go:2137

			err = querySource(function)
			if err != nil && function == "sys_get_functiondef" && isUndefinedFunction(err, function) {
				s.usePgFunctionDefinition = true
				function = "pg_get_functiondef"
				err = querySource(function)
			}
			if err != nil && !s.mode.postgresCatalog && function == "pg_get_functiondef" && isUndefinedFunction(err, function) {
				s.useLegacyRoutineDefinition = true
				err = queryLegacySource()
			}
		}
	} else if kind == "TRIGGER" {
		definitions, triggerErr := s.listTriggerDefinitionsFor(effective, relationName, name)
		if triggerErr != nil {
			err = triggerErr
		} else if len(definitions) == 1 {
			source = definitions[0]
		} else if len(definitions) > 1 {
			err = fmt.Errorf("trigger %q is ambiguous in schema %q; relation_name is required", name, effective)
		} else {
			err = sql.ErrNoRows
		}
	}
	if err != nil && err != sql.ErrNoRows {
		return nil, err
	}
	result := map[string]any{"name": name, "object_type": objectType, "schema": effective, "source": source}
	if kind == "TRIGGER" {
		result["editable"] = false
	}
	return result, nil
}

func (s *server) getMaterializedViewSource(schema, name string) (string, error) {
	catalog, prefix, function := "sys_catalog", "sys", "sys_get_viewdef"
	if s.mode.postgresCatalog {
		catalog, prefix, function = "pg_catalog", "pg", "pg_get_viewdef"

View on GitHub (pinned to c0390bff16)

Solutions

  1. Pass relation_name identifying the table that owns the trigger
  2. List triggers for the schema to see the duplicates and pick the correct relation
  3. Rename duplicate triggers so names are unique per schema
  4. If the driver supports it, filter by relation in the query instead of only by name

Example fix

// before
def, err := server.GetTrigger(ctx, "public", "audit_trigger", "")
// after: supply the owning relation
def, err := server.GetTrigger(ctx, "public", "audit_trigger", "orders")
Defensive patterns

Strategy: validation

Validate before calling

// Go: ensure trigger name is unique in schema before lookup
var n int
db.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)
if n > 1 {
    return fmt.Errorf("trigger %s is ambiguous in %s; pass relation_name", trigName, schema)
}

Try / catch

def, err := server.GetTrigger(ctx, schema, name, relation)
if err != nil && strings.Contains(err.Error(), "is ambiguous") {
    // list triggers and pick the one for the intended relation
    return listAndPickTrigger(server, schema, name)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/a48dd8e9cb2b0819. Report an issue: GitHub.