Write SQL queries Template#
When you use the Write SQL queries Template, you can input the data you want to extract and generate a prompt-driven example that produces a valid SQL query to retrieve that data.To try generating SQL based on your internal DB structure, modify the relevant sections of the prompt and run a test.
Writing Tips#
SQL should be written based on PostgreSQL syntax.
If the user does not provide sufficient information, first generate clarifying questions to collect the required details.
If the request is logically inconsistent, suggest a correct approach or query structure.
Configure WHERE, JOIN, and GROUP BY clauses at the minimal scope necessary to meet the stated data objective.
Extended Use Cases#
Enter your internal database structure in the [DB Table Description] section of the prompt to generate SQL using actual table and field names.
Template frequently used read queries to automate repeated requests.
Use the generated SQL draft as a reference when integrating with BI tools or data pipelines.
Notes for Modification#
If you edit the actual schema in [DB Table Description], keep column names, data types, and constraints identical to the real DB to avoid errors.
Be careful with reserved words and system column names (e.g., id, status, createdDate) to prevent case/type mismatches.
Before running the generated SQL, check for missing conditions (WHERE), aggregation mistakes, and proper handling of NULL values.
Modified at 2025-10-28 06:21:39