# Does drawDB Support PostgreSQL Table Inheritance?

> Yes drawDB supports PostgreSQL table inheritance with a dedicated UI field and generates correct SQL exports and migrations. Learn how drawDB handles this feature.

- Repository: [drawDB/drawdb](https://github.com/drawdb-io/drawdb)
- Tags: how-to-guide
- Published: 2026-08-14

---

**Yes, drawDB natively supports PostgreSQL table inheritance through an `inherits` property on table objects, generating proper `INHERITS` clauses in SQL exports and migrations while providing a dedicated UI field for parent table names.**

drawDB is an open-source entity-relationship diagram tool that supports database-specific features across multiple engines. For PostgreSQL users, drawDB offers first-class support for **table inheritance**, allowing you to model hierarchical relationships directly in your diagrams and export them as valid PostgreSQL DDL.

## How drawDB Implements Table Inheritance

### Schema Definition in src/data/schemas.js

According to the drawDB source code, inheritance relationships are defined at the schema level in [`src/data/schemas.js`](https://github.com/drawdb-io/drawdb/blob/main/src/data/schemas.js). Each table object in a diagram can contain an **`inherits`** property—an array of strings representing parent table names. This JSON schema ensures that inheritance data is preserved when saving or loading diagrams.

When you define a child table, the `inherits` array stores the names of all parent tables from which it derives columns and constraints.

### SQL Generation in postgres.js

When exporting diagrams to PostgreSQL, [`src/utils/exportSQL/postgres.js`](https://github.com/drawdb-io/drawdb/blob/main/src/utils/exportSQL/postgres.js) constructs the `CREATE TABLE` statements with an `inheritsClause`. If the table's `inherits` array contains entries, the exporter appends `) INHERITS (parent1, parent2, …)` immediately after the column definitions.

```sql
CREATE TABLE IF NOT EXISTS "vehicles" (
	"id" serial PRIMARY KEY,
	"make" text NOT NULL
);

CREATE TABLE IF NOT EXISTS "cars" (
	"doors" int NOT NULL
) INHERITS ("vehicles");

```

The `toPostgres` function specifically checks for the `inherits` property and builds the comma-separated list of parent tables, wrapping them in the standard PostgreSQL `INHERITS` syntax.

### Migration Support in diffToSQL.js

The migration generator located in [`src/utils/migrations/diffToSQL.js`](https://github.com/drawdb-io/drawdb/blob/main/src/utils/migrations/diffToSQL.js) applies the same inheritance logic when generating schema diffs. For `DB.POSTGRES`, the script adds the `INHERITS` clause after column definitions whenever the table object includes parent references.

If you modify inheritance relationships between diagram versions, the migration tool emits appropriate `DROP TABLE` and `CREATE TABLE` statements with the updated `INHERITS` clause, ensuring your PostgreSQL schema stays synchronized with your diagram.

## Configuring Inheritance in the drawDB UI

The table side-panel component at [`src/components/EditorSidePanel/TablesTab/TableInfo.jsx`](https://github.com/drawdb-io/drawdb/blob/main/src/components/EditorSidePanel/TablesTab/TableInfo.jsx) exposes an **Inherits** input field. You can type parent table names directly into this field, and the values are stored immediately in the diagram's table object under the `inherits` property.

This UI integration makes **drawDB PostgreSQL table inheritance** visually manageable without requiring manual JSON editing. The field accepts multiple parent table names, supporting PostgreSQL's multiple inheritance feature.

## Practical Example: Modeling Inherited Tables

Below is an example diagram fragment showing how drawDB represents inheritance in its JSON structure:

```json
{
  "tables": [
    {
      "id": 1,
      "name": "vehicles",
      "fields": [
        { "name": "id", "type": "serial", "primary": true },
        { "name": "make", "type": "text", "notNull": true }
      ],
      "inherits": []
    },
    {
      "id": 2,
      "name": "cars",
      "fields": [
        { "name": "doors", "type": "int", "notNull": true }
      ],
      "inherits": ["vehicles"]
    }
  ]
}

```

When exported to PostgreSQL, this generates the SQL shown in the previous section, with `"cars"` properly inheriting from `"vehicles"`.

## Summary

- drawDB stores inheritance relationships in the **`inherits`** array property of table objects, defined in [`src/data/schemas.js`](https://github.com/drawdb-io/drawdb/blob/main/src/data/schemas.js)
- The PostgreSQL exporter in [`src/utils/exportSQL/postgres.js`](https://github.com/drawdb-io/drawdb/blob/main/src/utils/exportSQL/postgres.js) generates `CREATE TABLE ... INHERITS (...)` statements automatically
- Migration scripts maintain inheritance through [`src/utils/migrations/diffToSQL.js`](https://github.com/drawdb-io/drawdb/blob/main/src/utils/migrations/diffToSQL.js) for PostgreSQL targets
- The UI provides an **Inherits** field in [`TableInfo.jsx`](https://github.com/drawdb-io/drawdb/blob/main/TableInfo.jsx) for visual management of parent tables
- This feature is PostgreSQL-specific; other database targets ignore the `inherits` property

## Frequently Asked Questions

### Can I use table inheritance with databases other than PostgreSQL in drawDB?

No. The `inherits` property is specific to PostgreSQL. When exporting to MySQL, SQL Server, or other supported databases, drawDB ignores the inheritance settings defined in [`src/data/schemas.js`](https://github.com/drawdb-io/drawdb/blob/main/src/data/schemas.js) and generates standard `CREATE TABLE` statements without the `INHERITS` clause.

### How do I modify an existing table's inheritance in drawDB?

Open the table in the side panel editor. In the **Inherits** field (managed by [`src/components/EditorSidePanel/TablesTab/TableInfo.jsx`](https://github.com/drawdb-io/drawdb/blob/main/src/components/EditorSidePanel/TablesTab/TableInfo.jsx)), add or remove parent table names as comma-separated values. When you generate a migration or export to PostgreSQL, [`src/utils/migrations/diffToSQL.js`](https://github.com/drawdb-io/drawdb/blob/main/src/utils/migrations/diffToSQL.js) will create the necessary `DROP TABLE` and `CREATE TABLE` statements with the updated `INHERITS` clause to reflect your changes.

### Does drawDB support multiple inheritance for PostgreSQL tables?

Yes. Since the `inherits` property is an array, you can specify multiple parent tables in [`src/data/schemas.js`](https://github.com/drawdb-io/drawdb/blob/main/src/data/schemas.js). The PostgreSQL exporter in [`src/utils/exportSQL/postgres.js`](https://github.com/drawdb-io/drawdb/blob/main/src/utils/exportSQL/postgres.js) will generate `INHERITS (parent1, parent2, parent3)` with all specified parent tables in the comma-separated list.

### Where is the inheritance data stored in drawDB project files?

Inheritance data is stored in the diagram's JSON structure under each table's `inherits` array, as defined in [`src/data/schemas.js`](https://github.com/drawdb-io/drawdb/blob/main/src/data/schemas.js). When you save or export your diagram, this array is preserved and used during SQL generation for PostgreSQL targets.