Execute custom SQL in PostgreSQL on a schedule

Recipe ToolsDatabase

What it does

When a specified interval triggers, this automation runs custom SQL in PostgreSQL. It queries the salesforce.opportunity and salesforce.address_usage__c tables, batches results into lists, and stops the job when complete.

Who it's for

Data and analytics teams who need to execute scheduled SQL queries in PostgreSQL without manual intervention.

How teams use this

Sync Salesforce data on schedule

Run the custom SQL query every night to extract opportunity and address records from PostgreSQL, keeping your data warehouse in sync with Salesforce without manual exports.

Generate reports for the sales team

Schedule the SQL query to run each Monday morning so sales operations can access fresh opportunity data in their reports. The same automation runs on a different schedule.

Filter results by a date range

Add a condition to the custom SQL so only records created or modified within the last 30 days are included in the query results. This reduces data volume processed.

How it works

  1. Start on a specified interval. The automation runs on a schedule you set, such as daily, weekly, or at a specific time each day.
  2. Query opportunity and address tables. Select rows from the salesforce.opportunity and salesforce.address_usage__c tables in PostgreSQL and batch the results into separate lists for processing.
  3. Build and query data lists. Create Opportunities and addresses lists from the batched results, then query those lists in a collection to prepare data for the final step.
  4. Execute custom SQL and stop. Run your custom SQL query in PostgreSQL using the prepared data, then stop the job when the query completes successfully.