# HV004 — fdw_invalid_data_type

> PostgreSQL SQLSTATE HV004 denotes a foreign-data-wrapper data type mismatch. Confirm the wrapper's type mapping and the local foreign-table definition.
---

# HV004 — fdw_invalid_data_type

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

`HV004` is the SQL/MED condition for a foreign-data-wrapper data type that cannot be used for the requested operation. The 18.6 core/contrib call scan found no resolved direct `HV004` report group, so this page does not claim a particular bundled message or SQL trigger.

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

| Field | Value |
| --- | --- |
| SQLSTATE | `HV004` |
| Condition | `fdw_invalid_data_type` |
| Status | `active` |
| Known present by | `9.1.0` |
| Locked snapshots | `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_FDW_INVALID_DATA_TYPE` |
| Aliases | `—` |

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

## Meaning and scope {#meaning}

The condition belongs to the FDW callback boundary: a wrapper may reject a local column type, a remote type mapping, or a value conversion. PostgreSQL's FDW documentation notes that a wrapper may raise an error for a data-type mismatch; it does not prescribe one universal mapping or message.

## Messages and diagnostics {#messages}

No fixed 18.6 message variant was resolved for this code. Keep the wrapper's `M`, `D`, `H`, source file/function, local column type, remote type, and operation. A remote server's type error must remain distinguishable from the wrapper's local SQLSTATE.

## Diagnosis {#diagnosis}

Identify the foreign table column and conversion direction, then inspect the wrapper's validator, deparser, and tuple conversion code at its pinned version. Compare the local catalog type, collation/typmod where relevant, and the remote type metadata. A generic cast failure or `22xxx` value error is not evidence for `HV004`.

## Response {#response}

Use a supported type mapping or alter the foreign-table definition after checking data compatibility. If conversion is implemented by an external wrapper, upgrade or configure that wrapper only after checking its compatibility contract. Do not retry an unchanged plan; a data-type mismatch is deterministic for the same metadata.

## Versions {#versions}

The catalogue observes `HV004` from 9.1.0 through 18.6 and 19 Beta 3. The available pre-9 definition scan did not observe it; no exact introduction version is claimed.

## Related {#related}

Compare [`HV006`](../hv006/) for inconsistent type descriptors and [`HV007`](../hv007/) for an invalid column name. [`42804`](../42804/) is a core datatype mismatch and has a different ownership boundary.

## Sources {#sources}

- [`errcodes.txt`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L467-L468) — definition, SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba`.
- [`FDW callback documentation`](https://www.postgresql.org/docs/18/fdwhandler.html#FDW-CALLBACKS-SCAN) — wrapper conversion/error contract.
- [Structured evidence](../data/evidence/hv004.json) — bounded scan and source boundary.
