Skip to content
cosmodev ~/tools/csv-to-sql

CSV → SQL 임포터

Data & DevOps

CSV 데이터를 SQL 임포트문으로 변환합니다: 배치 처리된 다중 행 INSERT, Postgres COPY FROM STDIN 블록, 또는 MySQL LOAD DATA 문. 숫자 열을 추론하고, 빈 필드에는 NULL을 출력하며, 헤더 이름을 정리하고 중복을 제거하여 SQL 식별자로 만듭니다.

형식
다이얼렉트
타입 추론

(문서는 영어)

What it does

Converts CSV text into SQL import statements in three formats:

  • INSERT — batched multi-row INSERT INTO … VALUES (…), (…); statements, with a configurable rows-per-statement batch size and dialect-aware rules (SQL / MySQL / Postgres).
  • COPY — a Postgres COPY … FROM STDIN WITH (FORMAT csv, HEADER true); block ending in the psql \. terminator, payload included.
  • LOAD DATA — a MySQL LOAD DATA LOCAL INFILE statement plus the CSV payload to save as the referenced file.

The first CSV row is the header. Header names are trimmed, sanitized into SQL identifiers (anything outside A–Z a–z 0–9 _ becomes _), de-duplicated deterministically (id, id → id, id_2), and empty headers become col<N>. With type inference on, fields that look like numbers emit bare and verbatim (007 stays 007, 1e3 stays 1e3) and empty fields emit NULL; with it off, every value is a quoted string. Strings double their single quotes ('O''Brien'); MySQL mode additionally escapes backslashes and control bytes. 100% client-side.

How to use it

  1. Paste CSV into CSV — a sample is prefilled. The first row must be the header.
  2. Set the Table name and pick a Format: INSERT, COPY, or LOAD DATA.
  3. For INSERT, optionally pick the Dialect, the Rows / statement batch size, and toggle Type inference. For LOAD DATA, set the referenced File name.
  4. The SQL renders live on the right with the row count in the header.
  5. Copy it, or Download as import.sql.

Examples

Typed INSERT — table users, sample input →

INSERT INTO "users" ("id", "name", "email", "country") VALUES
  (1, 'Ada Lovelace', 'ada@example.com', 'UK'),
  (2, 'Alan Turing', 'alan@example.com', 'UK'),
  (3, 'Hamilton, Margaret', 'margaret@example.com', 'US');

Empty fields become NULL — id,note with rows 1, and 2,hi → (1, NULL) and (2, 'hi').

Header sanitizing — User Name,user-id → columns "User_Name", "user_id".

COPY block — same input in COPY format →

COPY "users" ("id", "name", "email", "country") FROM STDIN WITH (FORMAT csv, HEADER true);
id,name,email,country
1,Ada Lovelace,ada@example.com,UK
…
\.

Good to know

  • Private: conversion is local — nothing leaves the browser.
  • Numeric text passes through verbatim, so large integers never lose precision and 1e3 is not rewritten as 1000.
  • COPY quoting always follows Postgres rules and LOAD DATA always follows MySQL rules, regardless of the INSERT dialect setting — each format matches its engine’s native syntax.
  • Run LOAD DATA output with mysql --local-infile=1; the payload after the statement is the file to save.
  • Postgres INSERT output also works for SQLite in most cases; pick SQL for the conservative baseline.
  • Related tools: JSON to SQL INSERT, JSON ↔ CSV Converter, SQL Playground.
소스 코드14개 언어

100% 클라이언트 측 · 데이터는 브라우저 밖으로 나가지 않습니다. 도움이 되었나요? 팀원에게 공유해 보세요.