Stripe
Stripe is an API driven online payment processing utility.
The Stripe Wrapper allows you to read data from Stripe within your Postgres database.
Restoring a logical backup of a database with a materialized view using a foreign table can fail. For this reason, either do not use foreign tables in materialized views or use them in databases with physical backups enabled.
Preparation
Before you can query Stripe, you need to enable the Wrappers extension and store your credentials in Postgres.
Enable Wrappers
Make sure the wrappers
extension is installed on your database:
_10create extension if not exists wrappers with schema extensions;
Enable the Stripe Wrapper
Enable the stripe_wrapper
FDW:
_10create foreign data wrapper stripe_wrapper_10 handler stripe_fdw_handler_10 validator stripe_fdw_validator;
Store your credentials (optional)
By default, Postgres stores FDW credentials inside pg_catalog.pg_foreign_server
in plain text. Anyone with access to this table will be able to view these credentials. Wrappers is designed to work with Vault, which provides an additional level of security for storing credentials. We recommend using Vault to store your credentials.
_10-- Save your Stripe API key in Vault and retrieve the `key_id`_10insert into vault.secrets (name, secret)_10values (_10 'stripe',_10 '<Stripe API key>'_10)_10returning key_id;
Connecting to Stripe
We need to provide Postgres with the credentials to connect to Stripe, and any additional options. We can do this using the create server
command:
_10create server stripe_server_10 foreign data wrapper stripe_wrapper_10 options (_10 api_key_id '<key_ID>', -- The Key ID from above, required if api_key_name is not specified._10 api_key_name '<key_Name>', -- The Key Name from above, required if api_key_id is not specified._10 api_url 'https://api.stripe.com/v1/', -- Stripe API base URL, optional. Default is 'https://api.stripe.com/v1/'_10 api_version '2024-06-20' -- Stripe API version, optional. Default is your Stripe account’s default API version._10 );
Create a schema
We recommend creating a schema to hold all the foreign tables:
_10create schema if not exists stripe;
Entities
The Stripe Wrapper supports data read and modify from Stripe API.
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Accounts | ✅ | ❌ | ❌ | ❌ | ❌ |
Balance | ✅ | ❌ | ❌ | ❌ | ❌ |
Balance Transactions | ✅ | ❌ | ❌ | ❌ | ❌ |
Charges | ✅ | ❌ | ❌ | ❌ | ❌ |
Checkout Sessions | ✅ | ❌ | ❌ | ❌ | ❌ |
Customers | ✅ | ✅ | ✅ | ✅ | ❌ |
Disputes | ✅ | ❌ | ❌ | ❌ | ❌ |
Events | ✅ | ❌ | ❌ | ❌ | ❌ |
Files | ✅ | ❌ | ❌ | ❌ | ❌ |
File Links | ✅ | ❌ | ❌ | ❌ | ❌ |
Invoices | ✅ | ❌ | ❌ | ❌ | ❌ |
Mandates | ✅ | ❌ | ❌ | ❌ | ❌ |
Meters | ✅ | ❌ | ❌ | ❌ | ❌ |
PaymentIntents | ✅ | ❌ | ❌ | ❌ | ❌ |
Payouts | ✅ | ❌ | ❌ | ❌ | ❌ |
Prices | ✅ | ❌ | ❌ | ❌ | ❌ |
Products | ✅ | ✅ | ✅ | ✅ | ❌ |
Refunds | ✅ | ❌ | ❌ | ❌ | ❌ |
SetupAttempts | ✅ | ❌ | ❌ | ❌ | ❌ |
SetupIntents | ✅ | ❌ | ❌ | ❌ | ❌ |
Subscriptions | ✅ | ✅ | ✅ | ✅ | ❌ |
Tokens | ✅ | ❌ | ❌ | ❌ | ❌ |
Topups | ✅ | ❌ | ❌ | ❌ | ❌ |
Transfers | ✅ | ❌ | ❌ | ❌ | ❌ |
Accounts
This is an object representing a Stripe account.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Accounts | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_13create foreign table stripe.accounts (_13 id text,_13 business_type text,_13 country text,_13 email text,_13 type text,_13 created timestamp,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'accounts'_13 );
Notes
- While any column is allowed in a where clause, it is most efficient to filter by
id
- Use the
attrs
jsonb column to access additional account details
Balance
This is an object representing your Stripe account's current balance.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Balance | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_10create foreign table stripe.balance (_10 balance_type text,_10 amount bigint,_10 currency text,_10 attrs jsonb_10)_10 server stripe_server_10 options (_10 object 'balance'_10 );
Notes
- Balance is a read-only object that shows the current funds in your Stripe account
- The balance is broken down by source types (e.g., card, bank account) and currencies
- Use the
attrs
jsonb column to access additional balance details like pending amounts - While any column is allowed in a where clause, filtering options are limited as this is a singleton object
Balance Transactions
This is an object representing funds moving through your Stripe account. Balance transactions are created for every type of transaction that comes into or flows out of your Stripe account balance.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Balance Transactions | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_16create foreign table stripe.balance_transactions (_16 id text,_16 amount bigint,_16 currency text,_16 description text,_16 fee bigint,_16 net bigint,_16 status text,_16 type text,_16 created timestamp,_16 attrs jsonb_16)_16 server stripe_server_16 options (_16 object 'balance_transactions'_16 );
Notes
- Balance transactions are read-only records of all funds movement in your Stripe account
- Each transaction includes amount, currency, fees, and net amount information
- Use the
attrs
jsonb column to access additional transaction details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- type
Charges
This is an object representing a charge on a credit or debit card. You can retrieve and refund individual charges as well as list all charges. Charges are identified by a unique, random ID.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Charges | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_16create foreign table stripe.charges (_16 id text,_16 amount bigint,_16 currency text,_16 customer text,_16 description text,_16 invoice text,_16 payment_intent text,_16 status text,_16 created timestamp,_16 attrs jsonb_16)_16 server stripe_server_16 options (_16 object 'charges'_16 );
Notes
- Charges are read-only records of payment transactions in your Stripe account
- Each charge includes amount, currency, customer, and payment status information
- Use the
attrs
jsonb column to access additional charge details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
Checkout Sessions
This is an object representing your customer's session as they pay for one-time purchases or subscriptions through Checkout or Payment Links. We recommend creating a new Session each time your customer attempts to pay.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Checkout Sessions | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_12create foreign table stripe.checkout_sessions (_12 id text,_12 customer text,_12 payment_intent text,_12 subscription text,_12 attrs jsonb_12)_12 server stripe_server_12 options (_12 object 'checkout/sessions',_12 rowid_column 'id'_12 );
Notes
- Checkout Sessions are read-only records of customer payment sessions in your Stripe account
- Each session includes customer, payment intent, and subscription information
- Use the
attrs
jsonb column to access additional session details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- payment_intent
- subscription
Customers
This is an object representing your Stripe customers. You can create, retrieve, update, and delete customers.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Customers | ✅ | ✅ | ✅ | ✅ | ❌ |
Usage
_13create foreign table stripe.customers (_13 id text,_13 email text,_13 name text,_13 description text,_13 created timestamp,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'customers',_13 rowid_column 'id'_13 );
Example operations:
_12-- create a new customer_12insert into stripe.customers(email, name, description)_12values ('jane@example.com', 'Jane Smith', 'Premium customer');_12_12-- update a customer_12update stripe.customers_12set name = 'Jane Doe'_12where email = 'jane@example.com';_12_12-- delete a customer_12delete from stripe.customers_12where id = 'cus_xxx';
Notes
- Customers can be created, retrieved, updated, and deleted through SQL operations
- Each customer can have an email, name, and description
- Use the
attrs
jsonb column to access additional customer details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
Disputes
This is an object representing a dispute that occurs when a customer questions your charge with their card issuer.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Disputes | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table stripe.disputes (_15 id text,_15 amount bigint,_15 currency text,_15 charge text,_15 payment_intent text,_15 reason text,_15 status text,_15 created timestamp,_15 attrs jsonb_15)_15 server stripe_server_15 options (_15 object 'disputes'_15 );
Notes
- Disputes are read-only records of customer payment disputes in your Stripe account
- Each dispute includes amount, currency, charge, and payment intent information
- Use the
attrs
jsonb column to access additional dispute details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- charge
- payment_intent
Events
This is an object representing events that occur in your Stripe account, letting you know when something interesting happens.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Events | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_11create foreign table stripe.events (_11 id text,_11 type text,_11 api_version text,_11 created timestamp,_11 attrs jsonb_11)_11 server stripe_server_11 options (_11 object 'events'_11 );
Notes
- Events are read-only records of activities in your Stripe account
- Each event includes type, API version, and timestamp information
- Use the
attrs
jsonb column to access additional event details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- type
Files
This is an object representing a file hosted on Stripe's servers.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Files | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_16create foreign table stripe.files (_16 id text,_16 filename text,_16 purpose text,_16 title text,_16 size bigint,_16 type text,_16 url text,_16 created timestamp,_16 expires_at timestamp,_16 attrs jsonb_16)_16 server stripe_server_16 options (_16 object 'files'_16 );
Notes
- Files are read-only records of files hosted on Stripe's servers
- Each file includes filename, purpose, size, type, and URL information
- Files may have an expiration date specified in expires_at
- Use the
attrs
jsonb column to access additional file details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- purpose
File Links
This is an object representing a link that can be used to share the contents of a File
object with non-Stripe users.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
File Links | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_13create foreign table stripe.file_links (_13 id text,_13 file text,_13 url text,_13 created timestamp,_13 expired bool,_13 expires_at timestamp,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'file_links'_13 );
Notes
- File Links are read-only records that provide shareable access to Stripe files
- Each link includes a reference to the file and a public URL
- Links can be configured to expire at a specific time
- Use the
expired
boolean to check if a link has expired - Use the
attrs
jsonb column to access additional link details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- file
Invoices
This is an object representing statements of amounts owed by a customer, which are either generated one-off or periodically from a subscription.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Invoices | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table stripe.invoices (_15 id text,_15 customer text,_15 subscription text,_15 status text,_15 total bigint,_15 currency text,_15 period_start timestamp,_15 period_end timestamp,_15 attrs jsonb_15)_15 server stripe_server_15 options (_15 object 'invoices'_15 );
Notes
- Invoices are read-only records of amounts owed by customers
- Each invoice includes customer, subscription, status, and amount information
- Invoices track billing periods with period_start and period_end timestamps
- Use the
attrs
jsonb column to access additional invoice details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- status
- subscription
Mandates
This is an object representing a record of the permission a customer has given you to debit their payment method.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Mandates | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_11create foreign table stripe.mandates (_11 id text,_11 payment_method text,_11 status text,_11 type text,_11 attrs jsonb_11)_11 server stripe_server_11 options (_11 object 'mandates'_11 );
Notes
- Mandates are read-only records of customer payment permissions
- Each mandate includes payment method, status, and type information
- Use the
attrs
jsonb column to access additional mandate details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
Meters
This is an object representing a billing meter that allows you to track usage of a particular event.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Meters | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_12create foreign table stripe.meter (_12 id text,_12 display_name text,_12 event_name text,_12 event_time_window text,_12 status text,_12 attrs jsonb_12)_12 server stripe_server_12 options (_12 object 'billing/meters'_12 );
Notes
- Meters are read-only records for tracking event usage in billing
- Each meter includes display name, event name, and time window information
- The status field indicates whether the meter is active
- Use the
attrs
jsonb column to access additional meter details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
Payment Intents
This is an object representing a guide through the process of collecting a payment from your customer.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Payment Intents | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_13create foreign table stripe.payment_intents (_13 id text,_13 customer text,_13 amount bigint,_13 currency text,_13 payment_method text,_13 created timestamp,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'payment_intents'_13 );
Notes
- Payment Intents are read-only records that guide the payment collection process
- Each intent includes customer, amount, currency, and payment method information
- The created timestamp tracks when the payment intent was initiated
- Use the
attrs
jsonb column to access additional payment intent details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
Payouts
This is an object representing funds received from Stripe or initiated payouts to a bank account or debit card of a connected Stripe account.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Payouts | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table stripe.payouts (_15 id text,_15 amount bigint,_15 currency text,_15 arrival_date timestamp,_15 description text,_15 statement_descriptor text,_15 status text,_15 created timestamp,_15 attrs jsonb_15)_15 server stripe_server_15 options (_15 object 'payouts'_15 );
Notes
- Payouts are read-only records of fund transfers
- Each payout includes amount, currency, and status information
- The arrival_date indicates when funds will be available
- The statement_descriptor appears on your bank statement
- Use the
attrs
jsonb column to access additional payout details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- status
Prices
This is an object representing pricing configurations for products to facilitate multiple currencies and pricing options.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Prices | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_14create foreign table stripe.prices (_14 id text,_14 active bool,_14 currency text,_14 product text,_14 unit_amount bigint,_14 type text,_14 created timestamp,_14 attrs jsonb_14)_14 server stripe_server_14 options (_14 object 'prices'_14 );
Notes
- Prices are read-only records that define product pricing configurations
- Each price includes currency, unit amount, and product reference
- The active boolean indicates if the price can be used
- The type field specifies the pricing model (e.g., one-time, recurring)
- Use the
attrs
jsonb column to access additional price details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- active
Products
This is an object representing all products available in Stripe.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Products | ✅ | ✅ | ✅ | ✅ | ❌ |
Usage
_15create foreign table stripe.products (_15 id text,_15 name text,_15 active bool,_15 default_price text,_15 description text,_15 created timestamp,_15 updated timestamp,_15 attrs jsonb_15)_15 server stripe_server_15 options (_15 object 'products',_15 rowid_column 'id'_15 );
Notes
- Products can be created, read, updated, and deleted
- Each product includes name, description, and active status
- The default_price links to the product's default Price object
- The updated timestamp tracks the last modification time
- Use the
attrs
jsonb column to access additional product details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- active
Refunds
This is an object representing refunds for charges that have previously been created but not yet refunded.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Refunds | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table stripe.refunds (_15 id text,_15 amount bigint,_15 currency text,_15 charge text,_15 payment_intent text,_15 reason text,_15 status text,_15 created timestamp,_15 attrs jsonb_15)_15 server stripe_server_15 options (_15 object 'refunds'_15 );
Notes
- Refunds are read-only records of charge reversals
- Each refund includes amount, currency, and status information
- The charge and payment_intent fields link to the original transaction
- The reason field provides context for the refund
- Use the
attrs
jsonb column to access additional refund details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- charge
- payment_intent
SetupAttempts
This is an object representing attempted confirmations of SetupIntents, tracking both successful and unsuccessful attempts.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
SetupAttempts | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_16create foreign table stripe.setup_attempts (_16 id text,_16 application text,_16 customer text,_16 on_behalf_of text,_16 payment_method text,_16 setup_intent text,_16 status text,_16 usage text,_16 created timestamp,_16 attrs jsonb_16)_16 server stripe_server_16 options (_16 object 'setup_attempts'_16 );
Notes
- SetupAttempts are read-only records of payment setup confirmation attempts
- Each attempt includes customer, payment method, and status information
- The setup_intent field links to the associated SetupIntent
- The usage field indicates the intended payment method usage
- Use the
attrs
jsonb column to access additional attempt details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- setup_intent
SetupIntents
This is an object representing a guide through the process of setting up and saving customer payment credentials for future payments.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
SetupIntents | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_15create foreign table stripe.setup_intents (_15 id text,_15 client_secret text,_15 customer text,_15 description text,_15 payment_method text,_15 status text,_15 usage text,_15 created timestamp,_15 attrs jsonb_15)_15 server stripe_server_15 options (_15 object 'setup_intents'_15 );
Notes
- SetupIntents are read-only records for saving customer payment credentials
- Each intent includes customer, payment method, and status information
- The client_secret is used for client-side confirmation
- The usage field indicates how the payment method will be used
- Use the
attrs
jsonb column to access additional intent details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- payment_method
Subscriptions
This is an object representing customer recurring payment schedules.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Subscriptions | ✅ | ✅ | ✅ | ✅ | ❌ |
Usage
_13create foreign table stripe.subscriptions (_13 id text,_13 customer text,_13 currency text,_13 current_period_start timestamp,_13 current_period_end timestamp,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'subscriptions',_13 rowid_column 'id'_13 );
Notes
- Subscriptions can be created, read, updated, and deleted
- Each subscription includes customer and currency information
- The current_period_start and current_period_end track billing cycles
- The rowid_column option enables modification operations
- Use the
attrs
jsonb column to access additional subscription details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- customer
- price
- status
Tokens
This is an object representing a secure way to collect sensitive card, bank account, or personally identifiable information (PII) from customers.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Tokens | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_13create foreign table stripe.tokens (_13 id text,_13 type text,_13 client_ip text,_13 created timestamp,_13 livemode boolean,_13 used boolean,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'tokens'_13 );
Notes
- Tokens are read-only, single-use objects for secure data collection
- Each token includes type information (card, bank_account, pii, etc.)
- The client_ip field records where the token was created
- The used field indicates if the token has been used
- Use the
attrs
jsonb column to access token details like card or bank information - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- type
- used
Top-ups
This is an object representing a way to add funds to your Stripe balance.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Top-ups | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_13create foreign table stripe.topups (_13 id text,_13 amount bigint,_13 currency text,_13 description text,_13 status text,_13 created timestamp,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'topups'_13 );
Notes
- Top-ups are read-only records of balance additions
- Each top-up includes amount and currency information
- The status field tracks the top-up state (e.g., succeeded, failed)
- Use the
attrs
jsonb column to access additional top-up details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- status
Transfers
This is an object representing fund movements between Stripe accounts as part of Connect.
Ref: Stripe docs
Operations
Object | Select | Insert | Update | Delete | Truncate |
---|---|---|---|---|---|
Transfers | ✅ | ❌ | ❌ | ❌ | ❌ |
Usage
_13create foreign table stripe.transfers (_13 id text,_13 amount bigint,_13 currency text,_13 description text,_13 destination text,_13 created timestamp,_13 attrs jsonb_13)_13 server stripe_server_13 options (_13 object 'transfers'_13 );
Notes
- Transfers are read-only records of fund movements between accounts
- Each transfer includes amount, currency, and destination information
- The destination field identifies the receiving Stripe account
- Use the
attrs
jsonb column to access additional transfer details - While any column is allowed in a where clause, it is most efficient to filter by:
- id
- destination
Query Pushdown Support
This FDW supports where
clause pushdown. You can specify a filter in where
clause and it will be passed to Stripe API call.
For example, this query
_10select * from stripe.customers where id = 'cus_xxx';
will be translated to a Stripe API call: https://api.stripe.com/v1/customers/cus_xxx
.
For supported filter columns for each object, please check out foreign table documents above.
Examples
Some examples on how to use Stripe foreign tables.
Basic example
_10-- always limit records to reduce API calls to Stripe_10select * from stripe.customers limit 10;_10select * from stripe.invoices limit 10;_10select * from stripe.subscriptions limit 10;
Query JSON attributes
_11-- extract account name for an invoice_11select id, attrs->>'account_name' as account_name_11from stripe.invoices where id = 'in_xxx';_11_11-- extract invoice line items for an invoice_11select id, attrs#>'{lines,data}' as line_items_11from stripe.invoices where id = 'in_xxx';_11_11-- extract subscription items for a subscription_11select id, attrs#>'{items,data}' as items_11from stripe.subscriptions where id = 'sub_xxx';
Data modify
_16-- insert_16insert into stripe.customers(email,name,description)_16values ('test@test.com', 'test name', null);_16_16-- update_16update stripe.customers_16set description='hello fdw'_16where id = 'cus_xxx';_16_16update stripe.customers_16set attrs='{"metadata[foo]": "bar"}'_16where id = 'cus_xxx';_16_16-- delete_16delete from stripe.customers_16where id = 'cus_xxx';
To insert into an object with sub-fields, we need to create the foreign table with column name exactly same as the API required. For example, to insert a subscription
object we can define the foreign table following the Stripe API docs:
_12-- create the subscription table for data insertion, the 'customer'_12-- and 'items[0][price]' fields are required._12create foreign table stripe.subscriptions (_12 id text,_12 customer text,_12 "items[0][price]" text -- column name will be used in API Post request_12)_12 server stripe_server_12 options (_12 object 'subscriptions',_12 rowid_column 'id'_12 );
And then we can insert a subscription like below:
_10insert into stripe.subscriptions(customer, "items[0][price]")_10values ('cus_Na6dX7aXxi11N4', 'price_1MowQULkdIwHu7ixraBm864M');
Note this foreign table is only for data insertion, it cannot be used in select
statement.