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

CSV to SQL इंपोर्टर

Data & DevOps

CSV डेटा को SQL इंपोर्ट statements में बदलें: batched multi-row INSERTs, Postgres COPY FROM STDIN block, या MySQL LOAD DATA statement। Numeric columns पहचानता है, खाली fields के लिए NULL देता है, और header names को साफ़ करके unique SQL identifiers बनाता है।

Format
Dialect
Type inference

(Documentation in English)

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 languages

100% client-side · your data never leaves your browser. Found this useful? Share it with a teammate.