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:

ColumnTypeDescription
idTEXTPaddle discount ID (e.g., dsc_abc123). Primary key.
statusTEXTDiscount status: active, archived, expired, used.
codeTEXTDiscount code for checkout. Can be null.
typeTEXTDiscount type: flat, flat_per_seat, or percentage.
amountTEXTDiscount amount or percentage (stored as text for precision).
currency_codeTEXTCurrency code for flat discounts. Null for percentage discounts.
enabled_for_checkoutBOOLEANWhether the discount can be applied at checkout.
dataJSONBComplete Paddle discount object stored as JSON.
livemodeBOOLEANWhether this is production data (true) or sandbox (false).
created_atTIMESTAMPTZTimestamp when discount was created in Paddle.
updated_atTIMESTAMPTZTimestamp when discount was last updated in Paddle.
synced_atTIMESTAMPTZTimestamp 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';
  • Subscriptions - Subscriptions with applied discounts
  • Transactions - Transactions with applied discounts
  • Prices - Pricing information for discounted items