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:

ColumnTypeDescription
idTEXTStripe customer ID (e.g., cus_abc123). Primary key.
emailTEXTCustomer's email address. Can be null if not provided.
nameTEXTCustomer's display name. Can be null.
descriptionTEXTOptional description field for notes about the customer.
currencyTEXTCustomer's default currency code (e.g., usd, gbp).
balanceINTEGERCustomer's current account balance in cents. Defaults to 0.
delinquentBOOLEANWhether the customer has overdue invoices. Defaults to false.
dataJSONBComplete Stripe customer object stored as JSON.
livemodeBOOLEANWhether this is a live mode customer (true) or test mode (false).
createdTIMESTAMPTZTimestamp when customer was created in Stripe.
synced_atTIMESTAMPTZTimestamp 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);