Paddle Discounts SQL Template
SQL table creation template for syncing Paddle discount data to your PostgreSQL database.
Updated: 14 Feb 2026
Paddle Discounts SQL Template
Create a database table to store Paddle discount data including codes, types, amounts, and checkout settings.
What Data is Synced?
The Paddle Discounts sync captures discount information from your Paddle account:
- Discount ID: Unique Paddle discount identifier (e.g.,
dsc_abc123) - Status: Discount status (active, archived, expired, used)
- Code: Discount code customers enter at checkout
- Type: Discount type (flat, flat_per_seat, percentage)
- Amount: Discount amount or percentage
- Currency: Currency code for flat discounts
- Checkout Enabled: Whether the discount is enabled for checkout
- Complete Data: Full Paddle discount object stored as JSONB
- Timestamps: Created, updated, and sync tracking timestamps
SQL Table Template
Table Schema Explanation
Here's what each column in the table represents:
| Column | Type | Description |
|---|---|---|
id | TEXT | Paddle discount ID (e.g., dsc_abc123). Primary key. |
status | TEXT | Discount status: active, archived, expired, used. |
code | TEXT | Discount code for checkout. Can be null. |
type | TEXT | Discount type: flat, flat_per_seat, or percentage. |
amount | TEXT | Discount amount or percentage (stored as text for precision). |
currency_code | TEXT | Currency code for flat discounts. Null for percentage discounts. |
enabled_for_checkout | BOOLEAN | Whether the discount can be applied at checkout. |
data | JSONB | Complete Paddle discount object stored as JSON. |
livemode | BOOLEAN | Whether this is production data (true) or sandbox (false). |
created_at | TIMESTAMPTZ | Timestamp when discount was created in Paddle. |
updated_at | TIMESTAMPTZ | Timestamp when discount was last updated in Paddle. |
synced_at | TIMESTAMPTZ | Timestamp when CLS last synced this discount record. Auto-updated. |
Sync Mode
This template uses full sync only. Each sync fetches all discount records from your Paddle account.
Usage Examples
After syncing, you can query your discount data using standard SQL:
-- Get all active discounts
SELECT id, code, type, amount
FROM paddle_discounts
WHERE status = 'active';
-- Find percentage discounts
SELECT id, code, amount
FROM paddle_discounts
WHERE type = 'percentage' AND status = 'active';
-- Get discounts enabled for checkout
SELECT id, code, type, amount
FROM paddle_discounts
WHERE enabled_for_checkout = true AND status = 'active';
-- Count discounts by type and status
SELECT type, status, COUNT(*) as count
FROM paddle_discounts
GROUP BY type, status;
-- Find a discount by code
SELECT id, type, amount, status
FROM paddle_discounts
WHERE code = 'SUMMER2026';
-- Get recently created discounts
SELECT id, code, type, amount, created_at
FROM paddle_discounts
WHERE created_at > NOW() - INTERVAL '30 days'
ORDER BY created_at DESC;
Common Customizations
The template includes performance indexes for status, code, livemode, and created_at columns.
Add Unique Index for Discount Codes
CREATE UNIQUE INDEX idx_paddle_discounts_code_unique
ON paddle_discounts(code)
WHERE code IS NOT NULL AND status = 'active';
Add Index for Type Lookups
CREATE INDEX idx_paddle_discounts_type
ON paddle_discounts(type)
WHERE status = 'active';
Related Templates
- Subscriptions - Subscriptions with applied discounts
- Transactions - Transactions with applied discounts
- Prices - Pricing information for discounted items