Overview
Database schemas evolve as business requirements change. New columns are introduced, existing fields are modified, and tables are added to accommodate new data requirements.
For data pipelines, the challenge is ensuring that these changes are reflected in the destination without disrupting ongoing data movement.
As part of our Schema Changes in Hevo series, this article demonstrates how Hevo handles one common scenario: adding a new column to an existing source table.
We'll use a PostgreSQL-to-Snowflake pipeline to introduce a new column, trigger a sync in Hevo, and verify the updated schema and data in Snowflake.
The Scenario
Consider a business that maintains customer information in PostgreSQL. Its CUSTOMER table initially stores information such as customer ID, name, address, phone number, and market segment.
Let's imagine your business now wants to introduce a new field, c_customer_tier, to classify customers into loyalty tiers such as Gold, Silver, and Bronze. This is a typical use case.
This requires a schema change in the source database.
The question is: How does Hevo accommodate this change in an existing pipeline, and how is it reflected in Snowflake?
See How Hevo Handles Schema Changes
Step-by-Step Guide to Syncing New Columns from Database to Warehouse
Step 1: Set Up the Pipeline
For this demonstration, we'll use:
Demo setup
| Component | Configuration |
|---|---|
| Source | PostgreSQL |
| Source Schema | TPC-H (tpch) |
| Source Table | CUSTOMER |
| Destination | Snowflake |
| Pipeline | PostgreSQL → Snowflake |
In Hevo:
- Log in to your Hevo account.
- Navigate to Pipelines and click Create Pipeline.
- Select PostgreSQL as the Source.
- Enter the PostgreSQL connection details and test the connection.
- Select Snowflake as the Destination and configure its connection.
- Under object selection, select the
tpch.customertable. - Configure the Schema Evolution Policy to Allow all changes or Allow column-level changes only.
- Complete the pipeline setup and allow the initial sync to finish.
Text version
Pipeline #330: PgSQL_Snowflake_Demo Source: Amazon RDS PostgreSQL 15 → Destination: Snowflake_SEAcc_S Status: Enabled Schedule: Syncs daily at 14:48 UTC
Tabs: Overview (selected) | Job History | Needs Attention (0) | Pipeline Setup | Objects | Transformation Jobs | Activity Log
Health: Pipeline is healthy
Last Run: Completed · Today, 5:57 PM · 2m 50s · 3 Events Next Run (ESTIMATED): In 22h · Tomorrow, 5:54 PM
Historical in Last 7 Days: 8.66M ingested | 8.66M loaded | 0 failed Incremental in Last 7 Days: 5 ingested | 5 loaded | 0 failed
Step 2: Examine the Existing Schema
Before making any changes, let's examine the original CUSTOMER table in PostgreSQL.
| 1 | SELECT * |
| 2 | FROM your_schema_name.customer |
| 3 | LIMIT 10; |
or
| 1 | SELECT column_name, data_type |
| 2 | FROM information_schema.columns |
| 3 | WHERE table_schema = 'your_schema_name' |
| 4 | AND table_name = 'customer' |
| 5 | ORDER BY ordinal_position; |
Text version
| # | column_name | data_type |
|---|---|---|
| 1 | c_custkey | integer |
| 2 | c_name | character varying |
| 3 | c_address | character varying |
| 4 | c_nationkey | integer |
| 5 | c_phone | character |
| 6 | c_acctbal | numeric |
| 7 | c_mktsegment | character |
| 8 | c_comment | character varying |
Next, verify the corresponding table in Snowflake:
| 1 | DESC TABLE YOUR_DATABASE.YOUR_SCHEMA.CUSTOMER; |
At this stage, both tables contain the original set of columns.
Text version
| # | name | type | kind | null? | default | primary key | unique key |
|---|---|---|---|---|---|---|---|
| 1 | C_CUSTKEY | NUMBER(38,0) | COLUMN | Y | null | Y | N |
| 2 | C_NAME | VARCHAR(100) | COLUMN | Y | null | N | N |
| 3 | C_ADDRESS | VARCHAR(160) | COLUMN | Y | null | N | N |
| 4 | C_NATIONKEY | NUMBER(38,0) | COLUMN | Y | null | N | N |
| 5 | C_PHONE | VARCHAR(60) | COLUMN | Y | null | N | N |
| 6 | C_ACCTBAL | NUMBER(15,2) | COLUMN | Y | null | N | N |
| 7 | C_MKTSEGMENT | VARCHAR(40) | COLUMN | Y | null | N | N |
| 8 | C_COMMENT | VARCHAR(468) | COLUMN | Y | null | N | N |
| 9 | __HEVO__INGESTED_AT | NUMBER(38,0) | COLUMN | Y | null | N | N |
| 10 | __HEVO__OP_TYPE | VARCHAR(4) | COLUMN | Y | null | N | N |
| 11 | __HEVO__SOURCE_MODIFIED_AT | NUMBER(38,0) | COLUMN | Y | null | N | N |
| 12 | __HEVO__MARKED_DELETED | BOOLEAN | COLUMN | Y | null | N | N |
| 13 | __HEVO__LOADED_AT | NUMBER(38,0) | COLUMN | Y | null | N | N |
Step 3: Add a New Column in PostgreSQL
Let's introduce the new customer tier field at the source.
Execute the following SQL statement in PostgreSQL:
| 1 | ALTER TABLE tpch.customer |
| 2 | ADD COLUMN c_customer_tier VARCHAR(20); |
The new column is now part of the CUSTOMER table.
Text version
| c_custkey | c_name | c_address | c_nationkey | c_phone | c_acctbal | c_mktsegment | c_comment | c_customer_tier |
|---|---|---|---|---|---|---|---|---|
| 1 | Customer#000000001 | IVhzIApeRb… | 15 | 25-989-741-2988 | 711.56 | BUILDING | to the eve… | NULL |
| 2 | Customer#000000002 | XSTf4,NCw… | 13 | 23-768-687-3665 | 121.65 | AUTOMOBILE | l accounts… | NULL |
| 3 | Customer#000000003 | MG9kdTD2… | 1 | 11-719-748-3364 | 7498.12 | AUTOMOBILE | deposits … | NULL |
| 4 | Customer#000000004 | XxVSJsLAGtn | 4 | 14-128-190-5944 | 2866.83 | MACHINERY | requests. … | NULL |
| 5 | Customer#000000005 | KvpyuHCplr… | 3 | 13-750-942-6364 | 794.47 | HOUSEHOLD | n account… | NULL |
| 6 | Customer#000000006 | sKZz0CsnM… | 20 | 30-114-968-4951 | 7638.57 | AUTOMOBILE | tions. eve… | NULL |
| 7 | Customer#000000007 | TcGe5gaZN… | 18 | 28-190-982-9759 | 9561.95 | AUTOMOBILE | ainst the ir… | NULL |
| 8 | Customer#000000008 | I0B10bB0Ay… | 17 | 27-147-574-9335 | 6819.74 | BUILDING | among th… | NULL |
| 9 | Customer#000000009 | xKiAFTjUsC… | 8 | 18-338-906-3675 | 8324.07 | FURNITURE | r theodolit… | NULL |
| 10 | Customer#000000010 | 6LrEaV6KR… | 5 | 15-741-346-9870 | 2753.54 | HOUSEHOLD | es regular … | NULL |
Step 4: Insert a Record with the New Column
To demonstrate the new column carrying actual data, let's insert a customer record with the customer tier set to Gold.
| 1 | INSERT INTO tpch.customer ( |
| 2 | c_custkey, c_name, c_address, c_nationkey, |
| 3 | c_phone, c_acctbal, c_mktsegment, c_comment, |
| 4 | c_customer_tier |
| 5 | ) |
| 6 | SELECT |
| 7 | (SELECT MAX(c_custkey) + 1 FROM tpch.customer), |
| 8 | 'Demo Customer', |
| 9 | '123 Demo Street', |
| 10 | c_nationkey, |
| 11 | '11-111-111-1111', |
| 12 | 1000.00, |
| 13 | 'BUILDING', |
| 14 | 'Customer added for schema change demo', |
| 15 | 'Gold' |
| 16 | FROM tpch.customer |
| 17 | ORDER BY c_custkey |
| 18 | LIMIT 1; |
Verify the new record:
| 1 | SELECT c_custkey, c_name, c_customer_tier |
| 2 | FROM tpch.customer |
| 3 | WHERE c_name = 'Demo Customer'; |
We now have a new column in the source and a new customer record containing a value in that column.
Text version
Query:
SELECT c_custkey, c_name, c_customer_tier FROM customer WHERE c_name = 'Demo Customer';
Result (1 row):
| c_custkey | c_name | c_customer_tier |
|---|---|---|
| 150001 | Demo Customer | Gold |
Step 5: Hevo Automatically Handles the Schema Change
Now that the source schema and data have changed, let's see how Hevo handles the update.
Hevo continuously syncs data from the source based on the configured pipeline schedule. During the next scheduled sync, Hevo detects and accommodates the newly added column, along with the new customer record.
No manual pipeline recreation or destination table modification is required. Hevo handles this automatically on every plan. See pricing for plan details.
Step 6: Verify the Changes in Snowflake
Once the next sync completes, navigate to Snowflake and inspect the CUSTOMER table.
First, verify that the new column is present:
| 1 | DESC TABLE YOUR_DATABASE.YOUR_SCHEMA.CUSTOMER; |
Text version
| # | name | type | kind | null? | default | primary key | unique key |
|---|---|---|---|---|---|---|---|
| 1 | C_CUSTKEY | NUMBER(38,0) | COLUMN | Y | null | Y | N |
| 2 | C_NAME | VARCHAR(100) | COLUMN | Y | null | N | N |
| 3 | C_ADDRESS | VARCHAR(160) | COLUMN | Y | null | N | N |
| 4 | C_NATIONKEY | NUMBER(38,0) | COLUMN | Y | null | N | N |
| 5 | C_PHONE | VARCHAR(60) | COLUMN | Y | null | N | N |
| 6 | C_ACCTBAL | NUMBER(15,2) | COLUMN | Y | null | N | N |
| 7 | C_MKTSEGMENT | VARCHAR(40) | COLUMN | Y | null | N | N |
| 8 | C_COMMENT | VARCHAR(468) | COLUMN | Y | null | N | N |
| 9 | __HEVO__INGESTED_AT | NUMBER(38,0) | COLUMN | Y | null | N | N |
| 10 | __HEVO__OP_TYPE | VARCHAR(4) | COLUMN | Y | null | N | N |
| 11 | __HEVO__SOURCE_MODIFIED_AT | NUMBER(38,0) | COLUMN | Y | null | N | N |
| 12 | __HEVO__MARKED_DELETED | BOOLEAN | COLUMN | Y | null | N | N |
| 13 | __HEVO__LOADED_AT | NUMBER(38,0) | COLUMN | Y | null | N | N |
| 14 | C_CUSTOMER_TIER | VARCHAR(80) | COLUMN | Y | null | N | N |
Next, inspect the records:
| 1 | SELECT |
| 2 | C_CUSTKEY, |
| 3 | C_NAME, |
| 4 | C_CUSTOMER_TIER |
| 5 | FROM YOUR_DATABASE.YOUR_SCHEMA.CUSTOMER |
| 6 | ORDER BY C_CUSTKEY |
| 7 | LIMIT 20; |
The destination should now reflect the updated schema.
- The new
C_CUSTOMER_TIERcolumn is available in Snowflake. - Existing records have
NULLvalues in the newly added column. - The newly inserted Demo Customer record has
Goldpopulated in the column.
Text version
| C_CUSTKEY | C_NAME | C_NATIONKEY | C_MKTSEGMENT | __HEVO__OP_TYPE | __HEVO__SOURCE_MODIFIED_AT | __HEVO__MARKED_DELETED | C_CUSTOMER_TIER |
|---|---|---|---|---|---|---|---|
| 1 | Customer#000000001 | 15 | BUILDING | R | null | FALSE | null |
| 2 | Customer#000000002 | 13 | AUTOMOBILE | R | null | FALSE | null |
| 3 | Customer#000000003 | 1 | AUTOMOBILE | R | null | FALSE | null |
| 4 | Customer#000000004 | 4 | MACHINERY | R | null | FALSE | null |
| 5 | Customer#000000005 | 3 | HOUSEHOLD | R | null | FALSE | null |
| 6 | Customer#000000006 | 20 | AUTOMOBILE | R | null | FALSE | null |
| 7 | Customer#000000007 | 18 | AUTOMOBILE | R | null | FALSE | null |
| 8 | Customer#000000008 | 17 | BUILDING | R | null | FALSE | null |
| 9 | Customer#000000009 | 8 | FURNITURE | R | null | FALSE | null |
Let's verify the new record separately:
| 1 | SELECT |
| 2 | C_CUSTKEY, |
| 3 | C_NAME, |
| 4 | C_CUSTOMER_TIER |
| 5 | FROM YOUR_DATABASE.YOUR_SCHEMA.CUSTOMER |
| 6 | WHERE C_NAME = 'Demo Customer'; |
Text version
Query:
SELECT c_custkey, c_name, c_customer_tier FROM SOLUTIONS_ENGINEERING_POC.TPCH_TPCH1G.CUSTOMER where c_custkey =150001;
Result (1 row):
| C_CUSTKEY | C_NAME | C_CUSTOMER_TIER |
|---|---|---|
| 150001 | Demo Customer | Gold |
Conclusion
Adding a new column to an existing table is a common example of schema evolution.
In this demonstration, we introduced a new column in PostgreSQL, inserted a record using the new field, triggered an incremental sync through Hevo, and verified the updated schema and data in Snowflake.
With Hevo's schema evolution capabilities, compatible source schema changes can be accommodated within existing pipelines, helping businesses keep their data infrastructure aligned with evolving requirements.
What Will We Cover Next in Schema Changes?
- Adding a New Column to an Existing Table (this article)
- Adding a New Table
- Renaming an Existing Column
- Dropping an Existing Column
- Changing a Column's Data Type