惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
阮一峰的网络日志
阮一峰的网络日志
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
P
Palo Alto Networks Blog
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cisco Talos Blog
Cisco Talos Blog
L
Lohrmann on Cybersecurity
AWS News Blog
AWS News Blog
J
Java Code Geeks
博客园_首页
Scott Helme
Scott Helme
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
V
Visual Studio Blog
Cloudbric
Cloudbric
Jina AI
Jina AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
S
SegmentFault 最新的问题
The Last Watchdog
The Last Watchdog
SecWiki News
SecWiki News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
W
WeLiveSecurity
K
Kaspersky official blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hacker News: Ask HN
Hacker News: Ask HN
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
量子位
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 三生石上(FineUI控件)
Recent Commits to openclaw:main
Recent Commits to openclaw:main

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
PostgreSQL 01003 오류 원인과 해결 방법 완벽 가이드
umzzil nng · 2026-05-28 · via DEV Community

umzzil nng

01003 null value eliminated in set function 는?

PostgreSQL 에러 코드 01003은 WARNING: null value eliminated in set function 메시지로 출력되며, 엄밀히는 에러가 아닌 경고(WARNING) 입니다. SUM(), AVG(), COUNT(column), MAX(), MIN() 등의 집계 함수(set function)를 사용할 때, 대상 컬럼에 NULL 값이 포함되어 있고 해당 NULL이 계산에서 자동으로 제외될 때 발생합니다. SQL 표준에 따라 집계 함수는 NULL을 무시하고 동작하는 것이 정상이지만, 개발자나 운영자가 이 사실을 인지하지 못할 경우 데이터 정합성 문제로 이어질 수 있어 PostgreSQL이 경고를 통해 명시적으로 알려주는 것입니다.


주요 발생 원인

1. 집계 함수 대상 컬럼에 NULL 값이 존재하는 경우

가장 흔한 원인입니다. 테이블 설계 시 특정 컬럼에 NOT NULL 제약을 걸지 않아 NULL이 저장된 상태에서 AVG(), SUM() 등을 사용하면 해당 경고가 발생합니다. 예를 들어 주문 금액(order_amount) 컬럼에 일부 레코드가 NULL인 상태에서 평균을 구하면, NULL 행은 계산에서 제외되어 실제 평균값이 왜곡될 수 있습니다.

2. LEFT JOIN 또는 OUTER JOIN 사용 후 집계 처리

LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN을 사용하면 매칭되지 않는 쪽의 컬럼 값이 NULL로 채워집니다. 이 상태에서 JOIN 결과를 집계하면, 의도하지 않은 NULL이 집계 함수에 전달되어 경고가 발생합니다. 조인 결과에 NULL이 포함됐다는 사실을 놓치기 쉽기 때문에 실무에서 특히 주의가 필요합니다.

3. 서브쿼리 또는 CASE 표현식에서 NULL 반환

서브쿼리나 CASE WHEN 구문에서 특정 조건에 맞지 않는 경우 명시적으로 NULL을 반환하거나, ELSE 절을 생략하여 묵시적으로 NULL이 반환되는 경우가 있습니다. 이 결과를 바로 집계 함수에 넘기게 되면 NULL이 제거되면서 경고가 발생하고, 집계 결과가 예상과 달라질 수 있습니다.


해결 방법

원인 1 해결: COALESCE 또는 NULLIF를 사용해 NULL을 기본값으로 치환

집계 전에 COALESCE()를 사용하여 NULL을 명시적인 기본값(0, 빈 문자열 등)으로 치환하면 경고를 제거하고 의도한 대로 계산할 수 있습니다.

-- 문제가 되는 쿼리 (order_amount에 NULL이 있을 경우 경고 발생)
SELECT AVG(order_amount) AS avg_amount
FROM orders;

-- 해결책 1: COALESCE로 NULL을 0으로 치환
SELECT AVG(COALESCE(order_amount, 0)) AS avg_amount
FROM orders;

-- 해결책 2: NULL 행 자체를 필터링 (NULL을 0으로 취급하지 않고 제외)
SELECT AVG(order_amount) AS avg_amount
FROM orders
WHERE order_amount IS NOT NULL;

-- 실제 NULL 개수를 사전에 확인하는 쿼리
SELECT
    COUNT(*) AS total_rows,
    COUNT(order_amount) AS non_null_rows,
    COUNT(*) - COUNT(order_amount) AS null_rows
FROM orders;

Enter fullscreen mode Exit fullscreen mode

실무 팁: COUNT(*)COUNT(column) 의 차이를 항상 명심하세요. COUNT(*)는 NULL 포함 전체 행 수를, COUNT(column)은 NULL을 제외한 행 수를 반환합니다.


원인 2 해결: OUTER JOIN 결과에서 NULL 처리

-- 문제가 되는 쿼리 (LEFT JOIN으로 인해 NULL 발생)
SELECT
    c.customer_id,
    SUM(o.order_amount) AS total_amount
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id;

-- 해결책 1: COALESCE로 NULL인 금액을 0으로 치환
SELECT
    c.customer_id,
    SUM(COALESCE(o.order_amount, 0)) AS total_amount
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id;

-- 해결책 2: 주문이 없는 고객을 명시적으로 구분
SELECT
    c.customer_id,
    CASE
        WHEN COUNT(o.order_id) = 0 THEN 0
        ELSE SUM(o.order_amount)
    END AS total_amount,
    COUNT(o.order_id) AS order_count
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id;

Enter fullscreen mode Exit fullscreen mode


원인 3 해결: CASE 표현식에서 ELSE 절 명시

-- 문제가 되는 쿼리 (ELSE 절 없이 NULL 묵시적 반환)
SELECT
    AVG(
        CASE
            WHEN product_category = 'ELECTRONICS' THEN sale_price
        END
    ) AS avg_electronics_price
FROM products;

-- 해결책: ELSE 절을 명시하여 NULL 반환 방지
SELECT
    AVG(
        CASE
            WHEN product_category = 'ELECTRONICS' THEN sale_price
            ELSE 0  -- 또는 업무 규칙에 맞는 기본값
        END
    ) AS avg_electronics_price
FROM products;

-- 더 나은 접근: 필터링 방식으로 특정 카테고리만 집계
SELECT
    AVG(sale_price) AS avg_electronics_price
FROM products
WHERE product_category = 'ELECTRONICS'
  AND sale_price IS NOT NULL;

-- FILTER 절 활용 (PostgreSQL 9.4+)
SELECT
    AVG(sale_price) FILTER (WHERE product_category = 'ELECTRONICS') AS avg_electronics_price,
    AVG(sale_price) FILTER (WHERE product_category = 'FURNITURE') AS avg_furniture_price
FROM products
WHERE sale_price IS NOT NULL;

Enter fullscreen mode Exit fullscreen mode


경고 자체를 억제해야 하는 경우 (임시방편, 권장하지 않음)

-- 세션 단위로 경고 메시지를 억제 (근본적인 해결책이 아님)
SET client_min_messages = 'ERROR';

-- 특정 쿼리 실행
SELECT AVG(score) FROM exam_results;

-- 세션 복구
RESET client_min_messages;

Enter fullscreen mode Exit fullscreen mode

⚠️ 주의: 경고 억제는 문제를 숨길 뿐 해결하지 않습니다. 운영 환경에서는 반드시 근본 원인을 파악하고 데이터 또는 쿼리를 수정하는 방식으로 대응하세요.


예방 방법

1. 테이블 설계 단계에서 NOT NULL 제약 조건 및 DEFAULT 값 적극 활용

집계 대상이 될 수치형 컬럼(금액, 수량, 점수 등)은 가능한 한 NOT NULL DEFAULT 0 제약을 부여하여 설계 단계에서 NULL 유입을 원천 차단합니다. 이미 운영 중인 테이블이라면 데이터를 정제한 뒤 제약 조건을 추가하는 마이그레이션 작업을 계획하는 것이 좋습니다.

-- 테이블 생성 시 NOT NULL 및 DEFAULT 설정
CREATE TABLE orders (
    order_id     SERIAL PRIMARY KEY,
    customer_id  INT NOT NULL,
    order_amount NUMERIC(12, 2) NOT NULL DEFAULT 0,
    created_at   TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 기존 테이블에 NOT NULL 및 DEFAULT 추가 (데이터 정제 후)
UPDATE orders SET order_amount = 0 WHERE order_amount IS NULL;
ALTER TABLE orders ALTER COLUMN order_amount SET NOT NULL;
ALTER TABLE orders ALTER COLUMN order_amount SET DEFAULT 0;

Enter fullscreen mode Exit fullscreen mode

2. 집계 쿼리 작성 시 NULL 검증 쿼리를 습관화

운영 쿼리를 작성하기 전, 대상 컬럼의 NULL 분포를 사전에 확인하는 습관을 들입니다. CI/CD 파이프라인이나 데이터 품질 체크 프로세스에 NULL 비율 모니터링 쿼리를 포함시키면 배포 전에 문제를 감지할 수 있습니다.

-- NULL 비율 점검 쿼리 (배포 전 데이터 품질 체크 용도)
SELECT
    column_name,
    COUNT(*) AS total,
    COUNT(column_name) AS non_null_count,
    COUNT(*) - COUNT(column_name) AS null_count,
    ROUND(
        (COUNT(*) - COUNT(column_name))::NUMERIC / NULLIF(COUNT(*), 0) * 100,
        2
    ) AS null_ratio_pct
FROM (
    SELECT order_amount AS column_name FROM orders
) sub;

Enter fullscreen mode Exit fullscreen mode


관련 에러

  • 22003 (numeric_value_out_of_range): SUM() 집계 중 NULL 처리 후 결과값이 컬럼의 데이터 타입 범위를 초과할 때 함께 나타날 수 있습니다.
  • 22012 (division_by_zero): NULL을 제거한 후 집계 결과가 0이 되어 이를 분모로 사용할 경우 발생합니다. AVG() 내부 연산이나 비율 계산 시 NULLIF(denominator, 0)으로 방어해야 합니다.
  • 42803 (grouping_error): GROUP BY 없이 일반 컬럼과 집계 함수를 혼용할 때 발생하며, NULL 처리 쿼리를 리팩터링하는 과정에서 실수로 함께 마주치는 경우가 많습니다.
  • P0002 (no_data_found): 집계 함수가 NULL을 모두 제거한 결과 반환 행이 없을 때, PL/pgSQL 블록 내에서 SELECT INTO와 함께 사용하면 발생할 수 있습니다.