sql-translation

Translate R function calls into database-specific SQL for dbplyr backends.

514|191|Updated Mar 28, 2017
One-click install
npx skills add https://github.com/tidyverse/dbplyr --skill sql-translation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-translation
Source: https://github.com/tidyverse/dbplyr/tree/main/.claude/skills/sql-translation
Command: npx skills add https://github.com/tidyverse/dbplyr --skill sql-translation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill automates the complex process of converting R functions into their correct SQL equivalents for various database backends. It ensures that data operations are consistent, efficient, and accurate when working with different databases through dbplyr.

Core Features & Use Cases

  • R-to-SQL Mapping: Provides a clear guide for defining how R functions (scalar, aggregate, window) are translated into database-specific SQL expressions.
  • Backend Integration: Directs you on how to add these translations to specific dbplyr backend files (e.g., SQLite, PostgreSQL, MySQL), extending dbplyr's capabilities.
  • Use Case: When a new R function like str_to_upper() needs to work with a PostgreSQL database via dbplyr, this skill guides you through adding the UPPER() SQL translation to the R/backend-postgres.R file, including the necessary research and testing steps.

Quick Start

Implement a new SQL translation for the R function my_custom_sum(x) to SUM(x) for the SQLite backend, ensuring it handles NULLs correctly.

Frequently Asked Questions about sql-translation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I translate R functions to SQL for database backends like PostgreSQL?

R-to-SQL translation in dbplyr maps R functions to database-specific SQL equivalents using sql_translator to define scalar, aggregate, and window translations. Add translations to backend files (e.g., R/backend-postgres.R) to extend dbplyr's capabilities across SQLite, PostgreSQL, MySQL, and MSSQL, ensuring consistent data operations.

What's the process for adding a new SQL translation to dbplyr?

Define the translation using sql_translator with the appropriate function category (scalar, aggregate, or window), research the target database's SQL syntax, add it to the backend file, document the change, run interactive tests, and format code. This enables R functions like str_to_upper() to work correctly with your chosen database.

Can I add custom SQL translations for SQLite, PostgreSQL, MySQL, and MSSQL?

Yes. dbplyr supports custom SQL translations for SQLite, PostgreSQL, MySQL, and MSSQL through backend-specific files. Each backend has its own translation definitions, allowing you to add support for new R functions tailored to each database's SQL dialect and NULL-handling behavior.

What types of R functions can be translated to SQL in dbplyr?

Scalar, aggregate, and window functions can be translated. Scalar functions operate on individual values, aggregate functions summarize data (like SUM or COUNT), and window functions perform row-by-row calculations within partitions. Each requires specific translation syntax matching your target database.

Why would I need to add a SQL translation instead of using the R function directly?

SQL translations push computation to the database for efficiency and correctness. Without translations, dbplyr cannot execute R functions remotely; adding translations ensures operations run natively in SQL, reducing data transfer and leveraging database optimization for large datasets.