Guide for researching SQL syntax and behavior for database backends. Use when you need to research how a SQL function, command, or feature works in a specific database before implementing it in dbplyr.
Use this skill when researching SQL syntax and behavior for any database backend before implementing translations or features in dbplyr.
SQL correctness is paramount in dbplyr. You MUST complete research and documentation BEFORE implementing any SQL-related code.
Use WebSearch to find official documentation for "{dialect} {function/command}":
Create research/{dialect}-{command}.md with the following structure:
# {Dialect} - {Function/Command}
## Summary
[1-2 sentence summary focused on R-to-SQL translation]
## Syntax
[Minimal syntax examples from official sources]
## Key behaviors
[Only behaviors that matter for dbplyr translation]
## Limitations
[Only restrictions that affect dbplyr usage]
## Sources
- [Source name](URL)
- [Source name](URL)
Documentation guidelines:
Cross-reference multiple sources when:
Best practices:
Only after completing research and documentation should you:
# PostgreSQL - POSITION
## Summary
Returns the starting position of a substring within a string (1-indexed).
## Syntax
POSITION(substring IN string)
## Key behaviors
- Returns integer position (1-indexed)
- Returns 0 if substring not found
- Case-sensitive by default
- NULL if any argument is NULL
## Sources
- [PostgreSQL String Functions](https://www.postgresql.org/docs/current/functions-string.html)
# SQL Server - STRING_AGG
## Summary
Concatenates string values with a specified separator, optionally ordering results.
## Syntax
STRING_AGG(expression, separator) [WITHIN GROUP (ORDER BY order_expression)]
## Key behaviors
- Available in SQL Server 2017+ (compatibility level 110+)
- Returns NULL for empty groups
- Separator must be a literal or variable, not an expression
- WITHIN GROUP clause is optional but commonly used for deterministic ordering
- Maximum output length is 2GB
## Limitations
- Not available in SQL Server 2016 or earlier
- Cannot use with DISTINCT (use subquery instead)
- Separator cannot be a computed expression
## Sources
- [SQL Server STRING_AGG](https://docs.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql)
- [Compatibility requirements](https://docs.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql#compatibility-support)
Before completing SQL research:
research/{dialect}-{function}.md