- Print
- PDF
Troubleshooting Custom SQL in Logic Blocks
The Custom SQL section in ACE Logic Blocks allows users to define advanced queries for retrieving and managing specific account data. While powerful, this feature can lead to common issues if queries are misconfigured. Below is a guide to troubleshoot and resolve problems related to the Custom SQL section.
How Custom SQL Fits with Auto-Generated SQL
In ACE, the Add Field section generates SQL statements dynamically, and the Custom SQL section extends this logic by appending additional filtering or conditions.
Key Characteristics of Custom SQL:
Starts with AND: Custom SQL must always begin with AND to align with the auto-generated WHERE clause. Without this, the query will fail.
Combining Auto-Generated SQL and Custom SQL
Auto-Generated SQL
The Add Field section in ACE Logic Blocks allows you to define specific logic conditions, which are automatically translated into SQL. The resulting SQL is displayed in the Preview SQL section at the bottom of the page.
Below is an example to demonstrate how Add Field inputs generate SQL:
Logic Conditions Specified in Add Field:
if “Account Agency 3” is not empty
Resulting SQL in the Preview Section:
The system dynamically translates the specified logic into SQL:
Adding Custom SQL
Use the Custom SQL section to append advanced conditions.
Key Considerations for Custom SQL
Always Start with AND
Your custom SQL must begin with AND to integrate with the auto-generated WHERE clause seamlessly.
Avoid Using Unsupported Fields or Tables
Problem: Referencing unavailable fields or tables can cause query errors.
Solution:
Use fields visible in the Logic Block Add Field interface, as these align with the query layout.
Be cautious when using Logic Blocks in Logic Conditions, as some fields may not be accessible in this context.
Validate Conditions Before Saving
Use the Test button to verify that the combined query retrieves the desired results.
Design with Query Context in Mind
For account selection workflows, the database layout typically matches the Logic Builder fields.
For workflow logic conditions, some fields may not be accessible due to query context limitations.
Common Issues and Resolutions
Syntax Errors in Custom SQL
Problem: Errors indicate invalid syntax when applying or testing the Logic Block.
Cause: Missing keywords, mismatched parentheses, or incorrect formatting.
Solution:
Double-check SQL syntax for proper use of AND, OR, parentheses (), and quotes '.
Test the query incrementally by adding conditions one at a time.
Incorrect Results Returned
Problem: Logic Block retrieves incorrect or unexpected accounts.
Cause: Overly broad, restrictive, or conflicting query conditions.
Solution:
Verify the accuracy of field names and conditions (e.g., COALESCE logic, date intervals).
Ensure logical operators (AND, OR) are used correctly.
Performance Issues with Large Datasets
Problem: Queries take too long or time out.
Cause: Inefficient query design or lack of indexing.
Solution:
Optimize queries by reducing unnecessary subqueries or filters.
Use indexed fields in WHERE clauses to improve performance.
Active Records Not Filtered Correctly
Problem: Query includes inactive accounts or incorrect demographic data.
Cause: Missing filters like AND demographic_phone.active = true.
Solution:
Ensure all necessary filters are included in both auto-generated and custom SQL.
Logic Block Fails to Apply Changes
Problem: Query executes, but no updates or actions are applied.
Cause: Query does not return the required identifiers for downstream actions.
Solution:
Verify that the query returns the correct account IDs or demographic phone IDs.
Test the Logic Block results before applying changes.
Best Practices for Using Custom SQL
Test Queries Frequently
Use the Test button to validate your query before saving the Logic Block.
Comment Your Code
Add comments in the Description field to document the purpose of each condition.
Start Simple
Begin with basic queries and add complexity incrementally.
Use Relative Dates
Use dynamic conditions like CURRENT_DATE - '30 days'::interval instead of hardcoded values.
Collaborate with Database Administrators
For complex queries or performance issues, consult with your database administrator for guidance.
When to Seek Support
If you encounter errors or unexpected behavior on any page in the ACE system, follow the steps below to ensure that our support team has the information needed to assist you effectively.
Steps to Report an Issue
Take a Screenshot:
Capture the entire page, including:
The details visible on the page (e.g., fields, statuses, or tasks).
Any error messages displayed.
The URL in your browser’s address bar.
Include Key Details:
In addition to the screenshot, provide the following information:
What you were doing: A brief explanation of the actions you were taking when the issue occurred.
Steps to reproduce: A clear description of how the issue can be replicated (if applicable).
Error messages: Copy or include the exact error message text, if any.
Contact Support:
Submit the screenshot and all relevant details to support.