# 42P17 — Invalid object definition

> Source-backed reference for PostgreSQL SQLSTATE 42P17.
---

# 42P17 — Invalid object definition

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

`42P17` (**invalid_object_definition**) Object definitions can conflict through inheritance, generated columns, or rewrite rules.

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

| Field | Value |
| --- | --- |
| SQLSTATE | `42P17` |
| Condition | `invalid_object_definition` |
| 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_INVALID_OBJECT_DEFINITION` |
| Aliases | `—` |

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

## Meaning {#meaning}

Object-definition validation covers object relationships and generated/rule definitions. Selected paths reject an inherited constraint conflict, a generated column referencing another generated column, and recursive rules.

## Diagnosis {#diagnosis}

Classify the object named in the message: relation inheritance, generated-column expression, or rewrite rule. Inspect pg_inherits and constraint inheritance, the full generated expression, or pg_rewrite rules; these paths require different repairs.

## Response {#response}

For an inherited-constraint conflict, compare the parent/child definitions and inheritance flags and align them with the intended inheritance contract; do not universally remove an inherited constraint. Make a generated expression depend only on permitted base columns, or break the rewrite-rule cycle. Recheck the resulting object graph before rerunning DDL; renaming alone does not repair a recursive rule. If an ERROR occurs inside an explicit transaction, `ROLLBACK` or `ROLLBACK TO` a pre-error savepoint before another DDL attempt.

## Messages {#messages}

Representative source messages include: message: `constraint "%s" conflicts with non-inherited constraint on relation "%s"`; message: `cannot use generated column "%s" in column generation expression`; DETAIL: `A generated column cannot reference another generated column.`; message: `infinite recursion detected in rules for relation "%s"`. Placeholders are filled by the actual object, column, or parameter.

## Versions {#versions}

The locked catalogue shows this condition by PostgreSQL 7.4; behavior here is fixed to PostgreSQL 18.6 source. Catalogue presence is a range boundary, not proof that every message or feature began in that release.

## Related {#related}

- [`42P16`](../42p16/)
- [`42P07`](../42p07/)

## Sources {#sources}

Source messages, line anchors, and evidence limits are recorded in [authored evidence](../data/evidence/42p17.json).

- `src/backend/catalog/heap.c:2820-2823` ([fixed source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/heap.c#L2820-L2823))
- `src/backend/catalog/heap.c:3237-3242` ([fixed source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/heap.c#L3237-L3242))
- `src/backend/rewrite/rewriteHandler.c:2164-2167` ([fixed source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/rewrite/rewriteHandler.c#L2164-L2167))
