Convert CSV to psql
Upload a .csv or .tsv file and get back a psql SQL script you can load straight into your database. Types are preserved rather than flattened to text. Free, no registration, up to 10MB.
Click to upload or drag and drop
CSV, Excel, SQLite, SQL, DBF (max 10 MB)
How your data is typed in psql
Generated from the converter's own psql type mapping — this is what it actually emits, not an example.
| Your data | psql type |
|---|---|
| Whole number | BIGINT |
| Decimal (money) | NUMERIC(10,2) |
| Floating point | DOUBLE PRECISION |
| True / false | BOOLEAN |
| Date | DATE |
| Date and time | TIMESTAMP |
| Short text | TEXT |
| Long text | TEXT |
| Binary data | BYTEA |
Working from a .csv file
A CSV file carries no header describing itself, so everything about it - the separator, the encoding, whether an empty field means nothing or means zero - has to be worked out from the bytes. That is where the risk in this conversion lives.
- →The separator is sniffed from the first 4 KB across comma, semicolon, tab and pipe, so a semicolon-separated file saved by Excel in a European locale needs no setting.
- →The UTF-8 byte-order mark Excel writes is stripped before the header row is read, so your first column is not named with an invisible character in front of it.
- →Types are decided from the first 10,000 data rows. A value further down that contradicts the type it settled on becomes NULL rather than failing the whole file.
- →The table is named after the file, with spaces and hyphens replaced by underscores: sales report.csv becomes sales_report.
Running the script through psql
psql is PostgreSQL's command-line client rather than the database itself, and the script is written to be fed straight into it. Everything here is about the tool you run, not about the server you run it against.
- →From inside a session already open, \i dump.sql runs the file without leaving the prompt. The script contains no backslash meta-commands of its own, so nothing in it can collide with yours.
- →There is no BEGIN and no COMMIT anywhere in the file. Statements commit as they go, so a failure halfway leaves the tables already created: pass -1 to wrap the whole load in a single transaction, or -v ON_ERROR_STOP=1 to stop at the first error instead of carrying on past it.
- →The script switches standard_conforming_strings on itself instead of trusting the server default, so it behaves identically against a session that has been moved off it.
- →It sets client_encoding to UTF8 for the same reason. The file is written as UTF-8 with nothing to announce that, and psql would otherwise decode it using whatever the client locale says.
Reading CSV
- →Leading zeros are preserved. A column containing 01234 is kept as text, never turned into the number 1234.
- →An empty cell becomes NULL, not an empty string — the two mean different things once the data is in a database.
- →Dates are only treated as dates when the format is unambiguous. 03/04/2025 could be March 4th or April 3rd, so it stays text unless another value in the column settles it.
Writing psql
- →Backslashes are left alone, because PostgreSQL treats them as ordinary characters — doubling them would corrupt every Windows path.
- →Auto-increment columns become GENERATED BY DEFAULT AS IDENTITY.
- →Binary data is written as bytea, and identifiers respect the 63-character limit.
What you get
A ZIP containing dump.sql, plus a README with the exact command to load it. If anything about your data needed a judgement call, a _warnings.txt explains it.
Load this dump into PostgreSQL: psql -U USER -d DATABASE -f dump.sql Create the database first if it does not exist: createdb -U USER DATABASE
Questions
- Is converting CSV to psql free?
- Yes. Files up to 10MB convert free with no account. There is a limit of five conversions per day per IP address.
- Will my CSV data keep its types in psql?
- Yes — that is the point. Whole numbers, decimals, dates and booleans are mapped to real psql types rather than everything becoming text. The mapping table above shows exactly what you get.
- Do you store my file?
- No. The file is written to a temporary directory, converted, and the directory is deleted as soon as your download has been sent.