---
title: Handling Composite-to-Single Primary Key Changes with Hevo
description: See how Hevo adapts when a PostgreSQL primary key changes from a composite key to a single column, keeping Snowflake data intact and replication running.
canonical_url: https://hevodata.com/engineering/handling-composite-to-single-primary-key-changes-with-hevo/
image: https://res.cloudinary.com/hevo/image/upload/v1796459656/hevo-engineering/posts/ljuyv0apkpr881jptpui.png
published_at: 2026-12-05T08:29:59.445869+00:00
updated_at: 2026-12-05T08:34:22.642575+00:00
author: Animesh Sharma
tags: [schema evolution, primary key, postgresql, snowflake]
category: Schema Evolution
content_type: article
word_count: 719
source: https://hevodata.com/engineering/handling-composite-to-single-primary-key-changes-with-hevo.md
---
# Handling Composite-to-Single Primary Key Changes with Hevo

> See how Hevo adapts when a PostgreSQL primary key changes from a composite key to a single column, keeping Snowflake data intact and replication running.

## Adapting to Evolving Data Models Without Disrupting Replication

As business requirements evolve, the way applications uniquely identify records can change. A table that initially uses a combination of two columns as its primary key may eventually move to a single-column primary key.

For data replication pipelines, this is an important schema change. The primary key determines how records are uniquely identified, so changes to its structure need to be reflected correctly in the destination.

**[Hevo](https://hevodata.com/) seamlessly handles primary-key structure changes, adapting to the updated key configuration while preserving existing destination data and continuing to replicate new records.**

Let's look at how this works in a PostgreSQL-to-Snowflake pipeline.

## The Scenario: Moving from a Composite Key to a Single-Column Key

Consider a procurement system that maintains information about parts and their suppliers.

Initially, a record is uniquely identified using a combination of `ps_partkey` and `ps_suppkey`. Together, these columns form a composite primary key.

As the business model evolves, each part is now associated with a single supplier in this dataset. This means `ps_partkey` alone is sufficient to uniquely identify each record.

The primary key therefore needs to change from:

- **Composite primary key:** `ps_partkey` + `ps_suppkey`
- **New primary key:** `ps_partkey`

Here's how Hevo handles this change.

[? Handling Composite-to-Single Primary Key Changes with Hevo](https://www.youtube.com/watch?v=XUPJ2H9QG6M)

_Watch Hevo adapt to a primary key change from (ps_partkey, ps_suppkey) to ps_partkey in Snowflake, end to end._

## Step 1: Inspect the Existing Source Table

Start by examining the `partsupp_pk_demo` table in PostgreSQL.

**`PostgreSQL`**

```sql
SELECT *
FROM tpch1g.partsupp_pk_demo
ORDER BY ps_partkey;
```

Next, inspect its primary-key definition:

**`PostgreSQL`**

```sql
SELECT
    kcu.column_name,
    kcu.ordinal_position
FROM information_schema.table_constraints tc
JOIN information_schema.key_column_usage kcu
    ON tc.constraint_name = kcu.constraint_name
   AND tc.table_schema = kcu.table_schema
WHERE tc.table_schema = 'tpch1g'
  AND tc.table_name = 'partsupp_pk_demo'
  AND tc.constraint_type = 'PRIMARY KEY'
ORDER BY kcu.ordinal_position;
```

Initially, both `ps_partkey` and `ps_suppkey` participate in identifying a unique record.

## Step 2: Verify the Existing Snowflake Data

Before changing the source, inspect the corresponding destination table.

**`Snowflake`**

```sql
DESC TABLE YOUR_DATABASE.YOUR_SCHEMA.PARTSUPP_PK_DEMO;
```

Check the existing records:

**`Snowflake`**

```sql
SELECT *
FROM YOUR_DATABASE.YOUR_SCHEMA.PARTSUPP_PK_DEMO
ORDER BY PS_PARTKEY;
```

This establishes the baseline for validating that the existing destination data remains intact after the primary-key change.

## Step 3: Change the Primary Key in PostgreSQL

The business model now requires `ps_partkey` to serve as the sole primary key.

First, remove the existing composite primary-key constraint:

**`PostgreSQL`**

```sql
ALTER TABLE tpch1g.partsupp_pk_demo
DROP CONSTRAINT partsupp_pk_demo_pkey;
```

Next, define `ps_partkey` as the new primary key:

**`PostgreSQL`**

```sql
ALTER TABLE tpch1g.partsupp_pk_demo
ADD CONSTRAINT partsupp_pk_demo_pkey
PRIMARY KEY (ps_partkey);
```

The source table now uses a single-column primary key instead of the original composite key.

Verify the updated definition:

**`PostgreSQL`**

```sql
SELECT
    kcu.column_name,
    kcu.ordinal_position
FROM information_schema.table_constraints tc
JOIN information_schema.key_column_usage kcu
    ON tc.constraint_name = kcu.constraint_name
   AND tc.table_schema = kcu.table_schema
WHERE tc.table_schema = 'tpch1g'
  AND tc.table_name = 'partsupp_pk_demo'
  AND tc.constraint_type = 'PRIMARY KEY'
ORDER BY kcu.ordinal_position;
```

The result should now show only `ps_partkey`.

## Step 4: Let Hevo Handle the Primary-Key Change

Once the source primary key is updated, Hevo processes the changed key configuration through the existing pipeline in the next incremental run.

Hevo adapts to the new primary key, moving from the combination of `ps_partkey` and `ps_suppkey` to `ps_partkey` alone.

The existing destination table and its historical records are retained. There is no need to recreate the pipeline or manually rebuild the destination table.

## Step 5: Insert a New Record Using the Updated Key

To validate replication after the change, insert a new record into PostgreSQL.

**`PostgreSQL`**

```sql
INSERT INTO tpch1g.partsupp_pk_demo
    (ps_partkey, ps_suppkey, ps_availqty, ps_supplycost, ps_comment)
VALUES
    (999999, 9999, 150, 35.50, 'New record after primary key change');
```

Verify the new source record:

**`PostgreSQL`**

```sql
SELECT *
FROM tpch1g.partsupp_pk_demo
WHERE ps_partkey = 999999;
```

This confirms that the source table accepts new records using the updated primary-key definition.

## Step 6: Verify the Updated Schema and Data in Snowflake

After Hevo processes the pipeline run, verify that the updated primary-key configuration and the newly inserted record are reflected in the Snowflake destination.

First, inspect the destination table's primary-key configuration and schema:

**`Snowflake`**

```sql
DESC TABLE YOUR_DATABASE.YOUR_SCHEMA.PARTSUPP_PK_DEMO;
```

Verify that `PS_PARTKEY` is now the primary key, replacing the earlier composite key of `PS_PARTKEY` and `PS_SUPPKEY`.

Next, verify that the newly inserted record is available:

**`Snowflake`**

```sql
SELECT *
FROM YOUR_DATABASE.YOUR_SCHEMA.PARTSUPP_PK_DEMO
WHERE PS_PARTKEY = 999999;
```

The new record should be present in the same destination table.

Finally, verify that the existing records have been retained:

**`Snowflake`**

```sql
SELECT COUNT(*) AS total_records
FROM YOUR_DATABASE.YOUR_SCHEMA.PARTSUPP_PK_DEMO;
```

The destination should contain all the original records along with the newly replicated record.

Together, these checks confirm that Hevo has reflected the updated primary-key configuration in Snowflake, retained the existing data, and successfully replicated new records into the same destination table.

## Step 7: Confirm Successful Pipeline Execution

Review the pipeline run details and **Job History** in Hevo.

The pipeline completes successfully, and the new record is replicated using the updated primary-key configuration without disrupting ongoing data replication.

## The Takeaway

Changes to primary-key definitions can affect how a data pipeline identifies and processes records. Moving from a composite key to a single-column key is one such change.

Hevo adapts to the updated primary-key structure, preserves existing destination data, and continues replicating new records into the same Snowflake table.

With Hevo, evolving source data models don't have to mean rebuilding existing pipelines or losing continuity in the warehouse.
