t8y2/dbx · error

synonym target is missing: %s.%s

Error message

synonym target is missing: %s.%s

What it means

getSynonymSource resolved a synonym in the XuguDB catalog, but the synonym's TargetName is empty, meaning the catalog row exists yet points at nothing (a dangling synonym). The driver refuses to emit a CREATE SYNONYM statement because its target cannot be determined. This is thrown before any DDL string is rendered.

Source

Thrown at agents/drivers/xugu/main.go:3572

	}
	if comment := strings.TrimSpace(xuguString(sequence.Comment)); comment != "" {
		builder.WriteString("\n  COMMENT ")
		builder.WriteString(quoteStringLiteral(comment))
	}
	builder.WriteString(";")
	return builder.String()
}

// getSynonymSource reconstructs synonym DDL from ALL_SYNONYMS. Public
// synonyms are exposed in the reserved database-global scope and therefore
// use PUBLIC syntax without a schema qualifier.
func (s *server) getSynonymSource(schema, name string) (map[string]any, error) {
	synonym, err := s.resolveCatalogSynonym(schema, name)
	if err != nil {
		return nil, err
	}
	if strings.TrimSpace(synonym.TargetName) == "" {
		return nil, fmt.Errorf("synonym target is missing: %s.%s", synonym.Schema, synonym.Name)
	}

	var builder strings.Builder
	if synonym.Public {
		builder.WriteString("CREATE PUBLIC SYNONYM ")
		builder.WriteString(quoteIdentifier(synonym.Name))
	} else {
		builder.WriteString("CREATE SYNONYM ")
		builder.WriteString(quoteIdentifier(synonym.Schema))
		builder.WriteByte('.')
		builder.WriteString(quoteIdentifier(synonym.Name))
	}
	builder.WriteString("\nFOR ")
	if targetSchema := strings.TrimSpace(synonym.TargetSchema.String); targetSchema != "" {
		builder.WriteString(quoteIdentifier(targetSchema))
		builder.WriteByte('.')
	}
	builder.WriteString(quoteIdentifier(synonym.TargetName))

View on GitHub (pinned to c0390bff16)

Solutions

  1. Query ALL_SYNONYMS (or the XuguDB equivalent) for the synonym and inspect its target column to confirm it is empty.
  2. Recreate the synonym with a valid target: DROP SYNONYM schema.name; CREATE SYNONYM schema.name FOR new_target;
  3. If the synonym is truly dangling and unneeded, drop it so catalog-driven DDL extraction no longer trips on it.
  4. If the target exists but the catalog field is blank, raise the issue with the DBA/XuguDB support — this indicates catalog corruption or a restore issue.

Example fix

-- before: dangling synonym
CREATE SYNONYM app.orders FOR sales.orders;  -- sales.orders later dropped
SELECT get_ddl('app', 'orders'); -- error: synonym target is missing: app.orders

-- after
CREATE SYNONYM app.orders FOR sales2.orders; -- point at an existing object
Defensive patterns

Strategy: validation

Validate before calling

rows, _ := db.Query(`SELECT TARGET_NAME FROM ALL_SYNONYMS WHERE UPPER(SCHEMA_NAME)=UPPER(?) AND UPPER(SYNONYM_NAME)=UPPER(?)`, schema, name)
var target sql.NullString
if rows.Next() { rows.Scan(&target) }
rows.Close()
if !target.Valid || strings.TrimSpace(target.String) == "" { return fmt.Errorf("synonym %s.%s has no target; fix catalog first", schema, name) }

Try / catch

var synErr *SynonymTargetMissingError
if errors.As(err, &synErr) { log.Warn("skipping dangling synonym", synErr.Schema, synErr.Name); continue }

Prevention

When it happens

Trigger: Calling the driver's synonym/source extraction path (getSynonymSource via schema-object DDL reconstruction) for a synonym whose catalog row has an empty TargetName — e.g. a synonym created against an object that was later dropped or a manually inserted/blank catalog entry.

Common situations: Dropping the underlying table/view/procedure without dropping the synonym first; database migrations that recreate objects under new names; corrupted or partially restored catalogs where the synonym target reference was lost.

Related errors


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