Overview
When applications and business needs change, the source data structure can also change. A column that originally holds numeric values may later need to hold larger numbers, a different data type, or more decimal precision.
These changes need to be reflected in the destination without disrupting existing data pipelines.
Hevo handles supported source-side data type changes and column widening by detecting schema changes and applying the corresponding updates at the destination. This allows pipelines to adapt as source data evolves, without requiring manual destination schema modifications.
Let's look at how this works with a PostgreSQL-to-Snowflake pipeline.
Let's Take a Scenario
Consider a wholesale business that manages customer orders in PostgreSQL and replicates its data into Snowflake for reporting and analysis.
At first, the business keeps order totals rounded to two decimal places. As the finance team wants to dig deeper into the numbers, they now need to keep four decimal places. This detail helps them handle taxes, discounts, and cost allocations with accuracy.
To support this, the engineering team changes the o_totalprice column in the PostgreSQL orders table from NUMERIC(15,2) to NUMERIC(18,4).
This is one example of how a source column can evolve. Let's see how Hevo handles the change and keeps the destination schema in sync.
See It in Action
Step 1: Check the Existing Schema and Data
We begin with an existing PostgreSQL-to-Snowflake pipeline replicating the orders table.
First, inspect the source column definition:
| 1 | SELECT |
| 2 | column_name, |
| 3 | data_type, |
| 4 | numeric_precision, |
| 5 | numeric_scale |
| 6 | FROM information_schema.columns |
| 7 | WHERE table_schema = 'tpch1g' |
| 8 | AND table_name = 'orders' |
| 9 | AND column_name = 'o_totalprice'; |
The column currently uses NUMERIC(15,2).
Text version
PostgreSQL (DbVisualizer): column definition of tpch1g.orders.o_totalprice before the change
SELECT
column_name,
data_type,
numeric_precision,
numeric_scale
FROM information_schema.columns
WHERE table_schema = 'tpch1g'
AND table_name = 'orders'
AND column_name = 'o_totalprice';
Result: 1 row (0.376 sec)
| column_name | data_type | numeric_precision | numeric_scale |
|---|---|---|---|
| o_totalprice | numeric | 15 | 2 |
The column is NUMERIC(15,2).
Next, check the corresponding destination definition:
| 1 | DESC TABLE YOUR_DATABASE.YOUR_SCHEMA.ORDERS; |
In Snowflake, the column is represented as NUMBER(15,2).
Text version
Snowflake: DESC TABLE SOLUTIONS_ENGINEERING_POC.TPCHV2__TPCH1G.ORDERS; before the change: 14 rows (74 ms); the first 6 are visible
| # | name | type | kind | null? | primary key | unique key |
|---|---|---|---|---|---|---|
| 1 | O_ORDERKEY | NUMBER(38,0) | COLUMN | Y | Y | N |
| 2 | O_CUSTKEY | NUMBER(38,0) | COLUMN | Y | N | N |
| 3 | O_ORDERSTATUS | VARCHAR(4) | COLUMN | Y | N | N |
| 4 | O_TOTALPRICE | NUMBER(15,2) | COLUMN | Y | N | N |
| 5 | O_ORDERDATE | DATE | COLUMN | Y | N | N |
| 6 | O_ORDERPRIORITY | VARCHAR(60) | COLUMN | Y | N | N |
Default and check are null for every column.
We also inspect a few existing records to establish the baseline:
| 1 | SELECT |
| 2 | o_orderkey, |
| 3 | o_custkey, |
| 4 | o_totalprice |
| 5 | FROM tpch1g.orders |
| 6 | ORDER BY o_orderkey |
| 7 | LIMIT 5; |
Text version
PostgreSQL (DbVisualizer): first 5 orders before the change: 5 rows (0.284 sec)
SELECT o_orderkey, o_custkey, o_totalprice
FROM tpch1g.orders
ORDER BY o_orderkey
LIMIT 5;
| o_orderkey | o_custkey | o_totalprice |
|---|---|---|
| 1 | 36901 | 173665.47 |
| 2 | 78002 | 46929.18 |
| 3 | 123314 | 193846.25 |
| 4 | 136777 | 32151.78 |
| 5 | 44485 | 144659.20 |
The same orders in Snowflake:
Text version
Snowflake: first 5 orders before the change: 5 rows (669 ms)
SELECT O_ORDERKEY, O_CUSTKEY, O_TOTALPRICE
FROM SOLUTIONS_ENGINEERING_POC.TPCHV2__TPCH1G.ORDERS
ORDER BY O_ORDERKEY
LIMIT 5;
| O_ORDERKEY | O_CUSTKEY | O_TOTALPRICE |
|---|---|---|
| 1 | 36901 | 173665.47 |
| 2 | 78002 | 46929.18 |
| 3 | 123314 | 193846.25 |
| 4 | 136777 | 32151.78 |
| 5 | 44485 | 144659.20 |
The values match PostgreSQL exactly.
Step 2: Widen the Source Column
We now increase the precision and scale of o_totalprice from NUMERIC(15,2) to NUMERIC(18,4).
| 1 | ALTER TABLE tpch1g.orders |
| 2 | ALTER COLUMN o_totalprice TYPE NUMERIC(18,4); |
Verify the updated definition:
| 1 | SELECT |
| 2 | column_name, |
| 3 | data_type, |
| 4 | numeric_precision, |
| 5 | numeric_scale |
| 6 | FROM information_schema.columns |
| 7 | WHERE table_schema = 'tpch1g' |
| 8 | AND table_name = 'orders' |
| 9 | AND column_name = 'o_totalprice'; |
Text version
PostgreSQL (DbVisualizer): column definition of tpch1g.orders.o_totalprice after the ALTER: 1 row (0.284 sec)
| column_name | data_type | numeric_precision | numeric_scale |
|---|---|---|---|
| o_totalprice | numeric | 18 | 4 |
The column is now NUMERIC(18,4) (previously NUMERIC(15,2)).
Step 3: Update an Existing Record
To validate that the additional precision is retained, we update an existing order with a value containing four decimal places.
| 1 | UPDATE tpch1g.orders |
| 2 | SET o_totalprice = o_totalprice + 0.0001 |
| 3 | WHERE o_orderkey = 1; |
Verify the updated record:
| 1 | SELECT |
| 2 | o_orderkey, |
| 3 | o_custkey, |
| 4 | o_totalprice |
| 5 | FROM tpch1g.orders |
| 6 | WHERE o_orderkey = 1; |
The order total changes from 173665.47 to 173665.4701.
Text version
PostgreSQL (DbVisualizer): updating order 1 and verifying it
UPDATE tpch1g.orders
SET o_totalprice = o_totalprice + 0.0001
WHERE o_orderkey = 1;
SELECT o_orderkey, o_custkey, o_totalprice
FROM tpch1g.orders
WHERE o_orderkey = 1;
Result: 1 row (0.291 sec)
| o_orderkey | o_custkey | o_totalprice |
|---|---|---|
| 1 | 36901 | 173665.4701 |
Previously 173665.47.
Step 4: Let Hevo Handle the Schema Change
With the source column updated, Hevo detects the data type change and handles the corresponding destination-side schema evolution.
In this example, there is an additional consideration: Snowflake does not support directly increasing the scale of an existing numeric column through a standard ALTER COLUMN operation.
Hevo handles this using its higher decimal scale mechanism. It creates a temporary wider decimal column, copies the existing values, replaces the original column, and retains the original column name.
Once the next scheduled sync completes, the updated schema and data are available in the destination without requiring us to manually recreate or modify the Snowflake column.
Step 5: Verify the Updated Schema and Data in Snowflake
We first inspect the destination table:
| 1 | DESC TABLE YOUR_DATABASE.YOUR_SCHEMA.ORDERS; |
Text version
Snowflake: DESC TABLE SOLUTIONS_ENGINEERING_POC.TPCHV2__TPCH1G.ORDERS; after the sync: 14 rows (48 ms); rows 9–14 are visible
| # | name | type | kind | null? | primary key | unique key |
|---|---|---|---|---|---|---|
| 9 | __HEVO__INGESTED_AT | NUMBER(38,0) | COLUMN | Y | N | N |
| 10 | __HEVO__OP_TYPE | VARCHAR(4) | COLUMN | Y | N | N |
| 11 | __HEVO__SOURCE_MODIFIED_AT | NUMBER(38,0) | COLUMN | Y | N | N |
| 12 | __HEVO__MARKED_DELETED | BOOLEAN | COLUMN | Y | N | N |
| 13 | __HEVO__LOADED_AT | NUMBER(38,0) | COLUMN | Y | N | N |
| 14 | O_TOTALPRICE | NUMBER(18,4) | COLUMN | Y | N | N |
O_TOTALPRICE is now NUMBER(18,4) (previously NUMBER(15,2) at position 4). It now appears as the last column, consistent with Hevo replacing the original column with a wider one under the same name.
Then verify the updated order:
| 1 | SELECT |
| 2 | O_ORDERKEY, |
| 3 | O_CUSTKEY, |
| 4 | O_TOTALPRICE |
| 5 | FROM YOUR_DATABASE.YOUR_SCHEMA.ORDERS |
| 6 | WHERE O_ORDERKEY = 1; |
Text version
Snowflake: verifying order 1 after the sync: 1 row (257 ms)
SELECT O_ORDERKEY, O_CUSTKEY, O_TOTALPRICE
FROM SOLUTIONS_ENGINEERING_POC.TPCHV2__TPCH1G.ORDERS
WHERE O_ORDERKEY = 1;
| O_ORDERKEY | O_CUSTKEY | O_TOTALPRICE |
|---|---|---|
| 1 | 36901 | 173665.4701 |
Matches the updated PostgreSQL value.
Finally, check a few existing records to confirm that the data remains available:
| 1 | SELECT |
| 2 | O_ORDERKEY, |
| 3 | O_TOTALPRICE |
| 4 | FROM YOUR_DATABASE.YOUR_SCHEMA.ORDERS |
| 5 | ORDER BY O_ORDERKEY |
| 6 | LIMIT 5; |
The destination now accommodates the increased decimal precision, and the updated order value is available with all four decimal places.
Text version
Snowflake: first 5 orders after the sync: 5 rows (389 ms)
SELECT O_ORDERKEY, O_TOTALPRICE
FROM SOLUTIONS_ENGINEERING_POC.TPCHV2__TPCH1G.ORDERS
ORDER BY O_ORDERKEY
LIMIT 5;
| O_ORDERKEY | O_TOTALPRICE |
|---|---|
| 1 | 173665.4701 |
| 2 | 46929.1800 |
| 3 | 193846.2500 |
| 4 | 32151.7800 |
| 5 | 144659.2000 |
Order 1 shows the updated value. Orders 2–5 keep their original values, now displayed at scale 4 (for example 46929.18 → 46929.1800). No data was lost.
Conclusion
Column definitions don't always remain static. As applications evolve, columns may need to accommodate larger values, different data types, or greater precision.
Hevo helps manage these changes by detecting supported source-side data type changes and handling the corresponding destination schema evolution. This reduces the need for manual destination modifications and allows existing pipelines to keep up with changing data requirements.