본문으로 건너뛰기
Skillpedia
API 및 서버 (백엔드)40k · #7331

postgresql-code-review

하는 일

이 도구는 PostgreSQL SQL 코드를 분석해 모범 사례를 따르는지, PostgreSQL 특유의 흔한 함정을 피하는지 확인합니다. JSONB와 배열 같은 데이터 형식, 데이터베이스 설계, 보안 사용 방식에 초점을 맞춥니다.

사용하는 경우

  • ✓PostgreSQL용 새 SQL 쿼리나 함수를 작성할 때.
  • ✓PostgreSQL 데이터베이스의 성능을 최적화하고 싶을 때.
  • ✓PostgreSQL 코드가 안전하고 표준을 따르는지 확인하고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/postgresql-code-review/SKILL.md

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

사용 방법

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

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

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

AI에게 요청하는 예시

“최적화와 모범 사례 관점에서 이 PostgreSQL SQL 코드를 검토해 주세요: [여기에 SQL 코드를 붙여 넣으세요]”

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

작동 방식

도구는 코드를 모범 사례와 흔한 PostgreSQL 전용 오류의 예시와 비교합니다. 인덱스 사용, 데이터 형식(JSONB, 배열, ENUM), 테이블 설계 같은 영역을 찾아 개선 방법을 제안합니다.

기술 내용 (원본 SKILL.md)

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

PostgreSQL Code Review Assistant

Expert PostgreSQL code review for ${selection} (or entire project if no selection). Focus on PostgreSQL-specific best practices, anti-patterns, and quality standards that are unique to PostgreSQL.

🎯 PostgreSQL-Specific Review Areas

JSONB Best Practices

-- ❌ BAD: Inefficient JSONB usage
SELECT * FROM orders WHERE data->>'status' = 'shipped';  -- No index support

-- ✅ GOOD: Indexable JSONB queries
CREATE INDEX idx_orders_status ON orders USING gin((data->'status'));
SELECT * FROM orders WHERE data @> '{"status": "shipped"}';

-- ❌ BAD: Deep nesting without consideration
UPDATE orders SET data = data || '{"shipping":{"tracking":{"number":"123"}}}';

-- ✅ GOOD: Structured JSONB with validation
ALTER TABLE orders ADD CONSTRAINT valid_status 
CHECK (data->>'status' IN ('pending', 'shipped', 'delivered'));

Array Operations Review

-- ❌ BAD: Inefficient array operations
SELECT * FROM products WHERE 'electronics' = ANY(categories);  -- No index

-- ✅ GOOD: GIN indexed array queries
CREATE INDEX idx_products_categories ON products USING gin(categories);
SELECT * FROM products WHERE categories @> ARRAY['electronics'];

-- ❌ BAD: Array concatenation in loops
-- This would be inefficient in a function/procedure

-- ✅ GOOD: Bulk array operations
UPDATE products SET categories = categories || ARRAY['new_category']
WHERE id IN (SELECT id FROM products WHERE condition);

PostgreSQL Schema Design Review

-- ❌ BAD: Not using PostgreSQL features
CREATE TABLE users (
    id INTEGER,
    email VARCHAR(255),
    created_at TIMESTAMP
);

-- ✅ GOOD: PostgreSQL-optimized schema
CREATE TABLE users (
    id BIGSERIAL PRIMARY KEY,
    email CITEXT UNIQUE NOT NULL,  -- Case-insensitive email
    created_at TIMESTAMPTZ DEFAULT NOW(),
    metadata JSONB DEFAULT '{}',
    CONSTRAINT valid_email CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$')
);

-- Add JSONB GIN index for metadata queries
CREATE INDEX idx_users_metadata ON users USING gin(metadata);

Custom Types and Domains

-- ❌ BAD: Using generic types for specific data
CREATE TABLE transactions (
    amount DECIMAL(10,2),
    currency VARCHAR(3),
    status VARCHAR(20)
);

-- ✅ GOOD: PostgreSQL custom types
CREATE TYPE currency_code AS ENUM ('USD', 'EUR', 'GBP', 'JPY');
CREATE TYPE transaction_status AS ENUM ('pending', 'completed', 'failed', 'cancelled');
CREATE DOMAIN positive_amount AS DECIMAL(10,2) CHECK (VALUE > 0);

CREATE TABLE transactions (
    amount positive_amount NOT NULL,
    currency currency_code NOT NULL,
    status transaction_status DEFAULT 'pending'
);

🔍 PostgreSQL-Specific Anti-Patterns

Performance Anti-Patterns

  • Avoiding PostgreSQL-specific indexes: Not using GIN/GiST for appropriate data types
  • Misusing JSONB: Treating JSONB like a simple string field
  • Ignoring array operators: Using inefficient array operations
  • Poor partition key selection: Not leveraging PostgreSQL partitioning effectively

Schema Design Issues

  • Not using ENUM types: Using VARCHAR for limited value sets
  • Ignoring constraints: Missing CHECK constraints for data validation
  • Wrong data types: Using VARCHAR instead of TEXT or CITEXT
  • Missing JSONB structure: Unstructured JSONB without validation

Function and Trigger Issues

-- ❌ BAD: Inefficient trigger function
CREATE OR REPLACE FUNCTION update_modified_time()
RETURNS TRIGGER AS $$
BEGIN
    NEW.updated_at = NOW();  -- Should use TIMESTAMPTZ
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- ✅ GOOD: Optimized trigger function
CREATE OR REPLACE FUNCTION update_modified_time()
RETURNS TRIGGER AS $$
BEGIN
    NEW.updated_at = CURRENT_TIMESTAMP;
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Set trigger to fire only when needed
CREATE TRIGGER update_modified_time_trigger
    BEFORE UPDATE ON table_name
    FOR EACH ROW
    WHEN (OLD.* IS DISTINCT FROM NEW.*)
    EXECUTE FUNCTION update_modified_time();

📊 PostgreSQL Extension Usage Review

Extension Best Practices

-- ✅ Check if extension exists before creating
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE EXTENSION IF NOT EXISTS "pg_trgm";

-- ✅ Use extensions appropriately
-- UUID generation
SELECT uuid_generate_v4();

-- Password hashing
SELECT crypt('password', gen_salt('bf'));

-- Fuzzy text matching
SELECT word_similarity('postgres', 'postgre');

…

자주 묻는 질문

'안티패턴'은 무엇인가요?

문제를 해결하는 것처럼 보이지만 나중에 성능 저하나 유지보수의 어려움 같은 더 큰 문제를 일으키는 흔한 해결책입니다.

JSONB는 무엇인가요?

PostgreSQL의 데이터 형식으로, JSON 형태로 데이터를 저장합니다. 다만 조회와 인덱싱에 더 효율적인 방식으로 저장하므로, 반정형 데이터에 이상적입니다.

RLS(행 수준 보안)는 무엇인가요?

특정 규칙에 따라 사용자가 테이블의 어떤 행을 보거나 수정할 수 있는지 제어하는 PostgreSQL 보안 기능입니다.

상세 정보

작성자의 원본 설명

PostgreSQL-specific code review assistant focusing on PostgreSQL best practices, anti-patterns, and unique quality standards. Covers JSONB operations, array usage, custom types, schema design, function optimization, and PostgreSQL-exclusive security features like Row Level Security (RLS).

repo: github/awesome-copilot

인기도

GitHub 스타
40k
순위
#7331
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬