Stripe Customers SQL Template
SQL table creation template for syncing Stripe customer data to your PostgreSQL database.
Updated: 15 Dec 2025
Stripe Customers SQL Template
Create a database table to store Stripe customer data including profiles, contact information, and custom metadata.
What Data is Synced?
The Stripe Customers sync captures essential customer information from your Stripe account:
- Customer ID: Unique Stripe customer identifier
- Contact Details: Email address and display name
- Description: Optional description field for customer notes
- Currency & Balance: Customer's default currency and account balance
- Account Status: Delinquent status and livemode flag
- Timestamps: When the customer was created in Stripe
- Custom Data: Complete Stripe customer object stored as JSONB
- Sync Tracking: Timestamp of when CLS last synced this record
SQL Table Template
Table Schema Explanation
Here's what each column in the table represents:
| Column | Type | Description |
|---|---|---|
id | TEXT | Stripe customer ID (e.g., cus_abc123). Primary key. |
email | TEXT | Customer's email address. Can be null if not provided. |
name | TEXT | Customer's display name. Can be null. |
description | TEXT | Optional description field for notes about the customer. |
currency | TEXT | Customer's default currency code (e.g., usd, gbp). |
balance | INTEGER | Customer's current account balance in cents. Defaults to 0. |
delinquent | BOOLEAN | Whether the customer has overdue invoices. Defaults to false. |
data | JSONB | Complete Stripe customer object stored as JSON. |
livemode | BOOLEAN | Whether this is a live mode customer (true) or test mode (false). |
created | TIMESTAMPTZ | Timestamp when customer was created in Stripe. |
synced_at | TIMESTAMPTZ | Timestamp when CLS last synced this customer record. Auto-updated. |
Usage Examples
After syncing, you can query your customer data using standard SQL:
-- Get all customers with a specific email domain
SELECT * FROM stripe_customers
WHERE email LIKE '%@example.com';
-- Find customers created in the last 30 days
SELECT * FROM stripe_customers
WHERE created > NOW() - INTERVAL '30 days';
-- Query customers by custom data field
SELECT * FROM stripe_customers
WHERE data->>'phone' IS NOT NULL;
-- Find delinquent customers
SELECT * FROM stripe_customers
WHERE delinquent = true;
-- Get customers by balance (those with credit)
SELECT * FROM stripe_customers
WHERE balance < 0
ORDER BY balance ASC;
Common Customizations
The template includes performance indexes for email, created, livemode, and delinquent columns. You can add additional table-specific customizations:
Add an Index for Name Searches
CREATE INDEX idx_stripe_customers_name
ON stripe_customers(name);
Add a Compound Index for Email and Livemode
CREATE INDEX idx_stripe_customers_email_livemode
ON stripe_customers(email, livemode);
Related Templates
- Invoices - Customer billing and invoice data
- Subscriptions - Recurring subscription records
- Payment Intents - Payment transaction records