<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Postgres on AiSlackin</title><link>https://aislackin.com/tags/postgres/</link><description>Recent content in Postgres on AiSlackin</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 16 Jun 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://aislackin.com/tags/postgres/index.xml" rel="self" type="application/rss+xml"/><item><title>csv2pg: CSV → PostgreSQL without the shell dance</title><link>https://aislackin.com/posts/2026-06-16-csv2pg/</link><pubDate>Tue, 16 Jun 2026 00:00:00 +0000</pubDate><guid>https://aislackin.com/posts/2026-06-16-csv2pg/</guid><description>&lt;p&gt;Most &amp;ldquo;import this CSV&amp;rdquo; advice ends with &lt;code&gt;psql&lt;/code&gt; invocations, &lt;code&gt;\copy&lt;/code&gt; meta-commands, and a schema you hand-write after eyeballing the data in a spreadsheet. I got tired of that ritual, so &lt;code&gt;csv2pg&lt;/code&gt; does the whole path in-process through psycopg3: analyze the file, infer the schema, create the table, stream the rows, verify the count, commit. No &lt;code&gt;psql&lt;/code&gt; binary involved anywhere.&lt;/p&gt;&#10;&lt;p&gt;The interesting part is the type inference. It samples up to 100 random rows per column to guess a candidate PostgreSQL type, then validates that guess against &lt;em&gt;every&lt;/em&gt; row in the file. If validation fails, the column widens to the next compatible type — up to five attempts — before falling back to &lt;code&gt;text&lt;/code&gt;. You get a tabulated summary plus a generated &lt;code&gt;.sql&lt;/code&gt; file before anything touches the database.&lt;/p&gt;</description></item></channel></rss>