# 42704 — undefined_object

> PostgreSQL SQLSTATE 42704: undefined_object, source-backed diagnosis and recovery guidance.
---

# 42704

## At a glance {#at-a-glance}

SQLSTATE `42704` is **undefined_object** in Class `42`. `42704` is undefined_object. The selected DROP TRIGGER path names a trigger absent from a real table and reports `trigger "%s" for table "%s" does not exist`; a real trigger can then be created and dropped.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| Field | Value |
| --- | --- |
| SQLSTATE | `42704` |
| Condition | `undefined_object` |
| Status | `active` |
| Known present by | `7.4` |
| Locked snapshots | `9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| Macros | `ERRCODE_UNDEFINED_OBJECT` |
| Aliases | `—` |

<!-- source facts: data/errcodes/42704.json -->
<!-- END SQLSTATE FACTS -->

## Meaning {#meaning}

`42704` is undefined_object. The object kind determines the lookup and the message: fixed branches include `type "%s" does not exist` after type-name resolution, `role "%s" does not exist` when a role lookup misses, `constraint "%s" for table "%s" does not exist` after scanning constraints for a relation OID, and `operator class "%s" does not exist for access method "%s"` after resolving a qualified or search-path opclass. The selected path is narrower: `get_trigger_oid` scans `pg_trigger` for the resolved relation OID and trigger name; when `DROP TRIGGER` requires an object and no row matches, it raises `trigger "%s" for table "%s" does not exist`, then the case creates and drops a real trigger as its repair lifecycle.

## Diagnosis {#diagnosis}

Classify the primary before changing anything. For the selected trigger branch, inspect the schema-qualified relation resolved by the DDL, exact trigger name (including quoted case), and migration order; a trigger can exist on another table while remaining absent from this relation because the source lookup is keyed by relation OID and name. For a type or role message, inspect the exact qualified name and the type/role catalog; for a constraint message, inspect the relation OID/name pair and migration order; for an opclass message, inspect the access method and schema/search_path used by the opclass lookup. A missing schema or unqualified relation is a different namespace/undefined-relation diagnosis, and a privilege failure is 42501. The missing-object `ERROR` leaves the selected autocommit session `IDLE`; inside an explicit `BEGIN`, it leaves the transaction `INERROR` until `ROLLBACK` or a suitable savepoint rollback. Distinguish it from 08003, which concerns a dblink handle, and 26000, which concerns a prepared statement name.

## Response {#response}

Repair the object category named by the message: correct the qualified name or search path, apply the prerequisite migration in dependency order, or create/rename the intended type, role, constraint, or operator class under its owning migration. For the selected trigger case only, operate on the intended relation explicitly, check owner, timing/event, row-level versus statement-level definition, and function, and then drop that exact trigger when the migration requires it. If an object is intentionally optional, choose an idempotent migration policy deliberately; do not use `CASCADE`, an unrelated object, or a generic create-then-drop sequence as a repair. After an explicit-transaction error, roll back the transaction or a suitable savepoint before retrying.

## Messages {#messages}

The selected `get_trigger_oid` branch emits an explicit `ERROR` with primary `trigger "%s" for table "%s" does not exist`; both trigger and table names are dynamic. Other fixed undefined-object branches emit `type "%s" does not exist`, `role "%s" does not exist`, `constraint "%s" for table "%s" does not exist`, or `operator class "%s" does not exist for access method "%s"`. A client exception without the server SQLSTATE and the primary for its object category is not sufficient to identify `42704`.

## Representative case {#case}

<!-- BEGIN SQLSTATE SNIPPET: missing_trigger -->

The page uses the same statements as the runner registry. Generated names such as `syntax_schema` and `syntax_role` are replaced by disposable runner values when executed.

```sql
CREATE TABLE syntax_schema.trigger_table (id integer);
DROP TRIGGER missing_trigger ON syntax_schema.trigger_table;
CREATE FUNCTION syntax_schema.trigger_function() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN RETURN NEW; END $$;
CREATE TRIGGER valid_trigger BEFORE INSERT ON syntax_schema.trigger_table FOR EACH ROW EXECUTE PROCEDURE syntax_schema.trigger_function();
DROP TRIGGER valid_trigger ON syntax_schema.trigger_table;
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'syntax_schema.trigger_table'::regclass AND NOT tgisinternal;
```

<!-- END SQLSTATE SNIPPET -->

The selected 18.6 run reports the structured diagnostic and passes the repair assertions; the 10.21 run passes the same case-specific checks. The downloadable case and evidence projections are [`42704 case JSON`](../data/cases/42704.json) and [`authored evidence`](../data/evidence/42704.json). The runner manifest is `verify/cases/42704/cases.json`, and the page SQL is checked against its shared registry.

## Versions {#versions}

The selected natural runtime scope is PostgreSQL 18.6 and 10.21; it does not infer behavior for every intermediate release.

## Related {#related}

- [`42703` — undefined_column](../42703/)
- [`26000` — related condition](../26000/)

## Sources {#sources}

- `src.errcodes.18.6` — fixed `errcodes.txt` definition at commit `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt)).
- `src.missing-trigger.18.6` — `src/backend/commands/trigger.c` at `REL_18_6` commit `724edf9bde9d356724ad384a2e196edc3c9f80f7`; fixed blob SHA-256 `0a539af85b0de1a04779f92202e7bfc77d85ae6da1747ea32527c67f39084fbd` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/trigger.c#L1406-L1409)).
- `src.missing-trigger.10.23` — `src/backend/commands/trigger.c` at `REL_10_23` commit `02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4`; fixed blob SHA-256 `dac7cdcbe2df1a1bbc77daa23e808b0c81ba8891c9895f10e8b270a15316e225` ([source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/commands/trigger.c#L1383-L1386)).
- `src.undefined-type.18.6` / `src.undefined-type.10.23` — fixed type-name lookup branches; blob SHA-256 `fe4670d2401141761096077c6495dd1b7d6a0baf33c9b903f25baee2f88ffd1e` / `729d30e50cea059ccfe13491fdc5f997ff98c227795693bf166a163925beb663` ([18.6 source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/objectaddress.c#L1618-L1624), [10.23 source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/catalog/objectaddress.c#L1493-L1509)).
- `src.undefined-role.18.6` / `src.undefined-role.10.23` — fixed `DROP ROLE` lookup branches; blob SHA-256 `aa8769a2577fff287301d6c82169262cca328515ae940d5a2be4b3e8c21617ed` / `9fc68a5a18c4bb5388cc817d2f3f2fcdc64f2752eaa429f78f54b0b443fb59ec` ([18.6 source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/user.c#L1129-L1135), [10.23 source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/commands/user.c#L1017-L1023)).
- `src.undefined-constraint.18.6` / `src.undefined-constraint.10.23` — fixed relation-constraint lookup branches; blob SHA-256 `0aa324acd355da955f8eb6cec17f1a0138277a8bebd2c6e999cd2a603d3bfa01` / `c90dff2d1d863e6b43102d762cec6e08b6c4ba40458045b525a14b49865d8a65` ([18.6 source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/pg_constraint.c#L1218-L1238), [10.23 source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/catalog/pg_constraint.c#L781-L801)).
- `src.undefined-opclass.18.6` / `src.undefined-opclass.10.23` — fixed access-method/opclass lookup branches; blob SHA-256 `f28ac0580c805553724dc623dd4e20f32de1a84db637e6ac3c6e3d296bd2fae5` / `85c646706908d13dc449bcffa6690d6ead8d326498051fef6b08f817347fa947` ([18.6 source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/opclasscmds.c#L145-L207), [10.23 source](https://github.com/postgres/postgres/blob/02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4/src/backend/commands/opclasscmds.c#L145-L207)).
- `src.calls.REL_18_6` / `src.calls.REL_10_23` — fixed call scans, SHA-256 `9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf` / `00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c`.
