<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Psql on FIZI</title><link>https://hoangnguyen689.github.io/fizi/tags/psql/</link><description>Recent content in Psql on FIZI</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 10 Apr 2025 10:00:00 +0900</lastBuildDate><atom:link href="https://hoangnguyen689.github.io/fizi/tags/psql/index.xml" rel="self" type="application/rss+xml"/><item><title>Batch records creation with Go and Postgres</title><link>https://hoangnguyen689.github.io/fizi/posts/batch_records_creation_with_go_and_postgres/</link><pubDate>Thu, 10 Apr 2025 10:00:00 +0900</pubDate><guid>https://hoangnguyen689.github.io/fizi/posts/batch_records_creation_with_go_and_postgres/</guid><description>&lt;p>Let&amp;rsquo;s talk about 2 problems in this post.&lt;/p>
&lt;ul>
&lt;li>batch insert in Postgres&lt;/li>
&lt;li>batch insert in SQLC (with Golang)&lt;/li>
&lt;/ul>
&lt;h2 id="resource-preparation">Resource preparation&lt;/h2>
&lt;p>To simplify, we will use an &lt;strong>users&lt;/strong> table with 4 fields: id(text, primary key), name(text), created_at and updated_at.
The insert data can be generated with &lt;a href="https://github.com/HoangNguyen689/pg-batch-play">&lt;strong>pg-batch-play&lt;/strong>&lt;/a> tool.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># generate 1M users data in SQL format with single INSERT command&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>go run main.go genbatchcreateuser -s &lt;span style="color:#ae81ff">1000000&lt;/span> -f sql -t singular
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Besides, we will also use &lt;strong>psql&lt;/strong> tool to observe, let&amp;rsquo;s enable the timing option.&lt;/p></description></item></channel></rss>