본문으로 건너뛰기
Skillpedia
데이터베이스6.2k · #14405

effective-dbt-sql

하는 일

이 스킬은 정확하고 읽기 쉬운 dbt 모델 SQL을 작성하기 위한 규칙을 제공합니다. dbt 모델과 지표를 쓰거나 바꾸는 분석 엔지니어를 위한 스킬입니다.

사용하는 경우

  • ✓dbt 모델 안에 SQL을 쓰려고 할 때.
  • ✓지표의 SQL 정의를 바꾸고 싶을 때.
  • ✓서브쿼리를 추가할지 기존 필드를 재사용할지 결정할 때.

스킬 링크

https://github.com/lightdash/lightdash/blob/main/skills/effective-dbt-sql/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/lightdash/lightdash/blob/main/skills/effective-dbt-sql/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“subscriptions dbt 모델에 이탈률 지표를 추가해 주세요. 같은 로직을 반복하지 말고, 이미 있는 필드를 재사용해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 가능하면 기존 필드를 재사용하고, 바깥 행마다 달라지는 상관 서브쿼리를 피하며, 복잡한 로직에는 CTE를 쓰라고 에이전트에게 지시합니다. 또한 저장소에 이미 쓰이는 스타일에 맞추라고 요청합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Effective dbt SQL

Write dbt model SQL that is correct, readable, and idiomatic. This skill is about the semantics of the SQL you write — not naming or formatting.

Scope

Use this when you are about to write or change SQL inside a dbt model (.sql), or a metric/dimension whose value is defined by SQL.

This skill covers semantics only. It does not prescribe naming schemes, file layout, or indentation. For those, follow the rule below.

Match the target repo first. These are fallback defaults, not mandates. Before applying any rule, read the models around the one you are changing and match the repo's established conventions where they differ. Apply these rules to new or changed SQL only — do not reformat, rename, or restructure existing code that already works.

The rules

  1. Reuse before you re-derive. If the value you are asked for is already expressed by an existing dimension or metric — or by two of them combined — compose those fields instead of writing new SQL to recompute it. Read the model's existing dimensions/metrics before adding one. See reuse-over-subqueries.

  2. No correlated subqueries. Never compute a value with a subquery that references the outer query's rows (a per-row correlated subquery in SELECT or WHERE). Reuse an existing field, or join to an aggregated CTE instead. This is the single most common mistake. See cte-pipelines.

  3. CTEs over nested subqueries. Structure a query as a pipeline of named CTEs, each referenced by the next, ending in a final select. Prefer this over subqueries nested inside from/where. See cte-pipelines.

  4. Explicit joins. Always state the join type (inner/left/…) and the on condition. Never comma-join. Know the grain: a join that fans out rows silently changes every downstream aggregate.

  5. Explicit columns. Select named columns rather than select * when adding or changing what a model emits, so a change to an upstream model can't silently alter this model's output. (A pass-through select * from final at the very end of a CTE pipeline is fine — the columns are already pinned by the CTEs.)

  6. Don't break references. Before editing a model's SQL, read the source()/ref() models it selects from. Do not rename or remove a column that downstream models or schema.yml reference without checking the impact first.

Not in scope

  • Emitted-type / casting safety (e.g. boolean-vs-numeric column types): follow the warehouse skill the system prompt points you to (/home/user/.lightdash-skills/). This skill does not restate casting rules.
  • Naming and formatting conventions: match the target repo (see the rule above).
자주 묻는 질문

이름이나 서식도 바꾸나요?

아니요, 스킬은 이름이나 배치가 아니라 SQL의 의미를 다룹니다.

기존 코드를 다시 쓰나요?

아니요, 스킬은 새로 만들거나 바뀐 SQL에만 적용되며, 작동하는 코드는 다시 쓰지 않습니다.

상관 서브쿼리란 무엇인가요?

바깥 쿼리의 행을 참조하는 서브쿼리이며, 스킬은 이를 피하라고 말합니다.

상세 정보

작성자의 원본 설명

Use when writing or modifying dbt model SQL — deciding whether to add a subquery or reuse an existing dimension/metric, structuring a query, joining models, or refactoring a metric's SQL. Encodes SQL semantic-correctness rules: reuse existing fields, prefer CTEs over correlated subqueries, and make joins and column lists explicit.

repo: lightdash/lightdash

인기도

GitHub 스타
6.2k
순위
#14405
라이선스
—
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬