<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Postgresql on Jake Worth</title><link>https://jakeworth.com/tags/postgresql/</link><description>Recent content in Postgresql on Jake Worth</description><image><title>Jake Worth</title><url>https://jakeworth.com/twittercard.png</url><link>https://jakeworth.com/twittercard.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 01 Jul 2026 10:04:17 -0500</lastBuildDate><atom:link href="https://jakeworth.com/tags/postgresql/index.xml" rel="self" type="application/rss+xml"/><item><title>Why Is It Called PostgreSQL?</title><link>https://jakeworth.com/tils/history-of-the-postgresql-name/</link><pubDate>Wed, 10 Nov 2021 11:04:17 -0500</pubDate><guid>https://jakeworth.com/tils/history-of-the-postgresql-name/</guid><description>&lt;p&gt;PostgreSQL was originally named &amp;ldquo;POSTGRES&amp;rdquo;— all caps. The name was chosen
because it was the successor (&amp;ldquo;post-&amp;rdquo;) to the &amp;ldquo;Ingres&amp;rdquo; database. As the system
adopted SQL standards and features, the &amp;ldquo;ql&amp;rdquo; as added and capitalization
refined.&lt;/p&gt;</description></item><item><title>Query the Size of Postgres Array</title><link>https://jakeworth.com/tils/query-the-size-of-postgres-array/</link><pubDate>Sun, 14 Feb 2016 16:57:20 -0600</pubDate><guid>https://jakeworth.com/tils/query-the-size-of-postgres-array/</guid><description>&lt;p&gt;Today I learned how to query the size of a Postgres array. There are (at least) two methods that work.&lt;/p&gt;
&lt;p&gt;The first is &lt;code&gt;array_length&lt;/code&gt;. This requires you to know the array dimension you seek; a useful filter, although most of the time this will probably be &lt;code&gt;1&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;hr&lt;span style="color:#f92672"&gt;-&lt;/span&gt;til_development&lt;span style="color:#f92672"&gt;=#&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;select&lt;/span&gt; title &lt;span style="color:#66d9ef"&gt;from&lt;/span&gt; posts
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;hr&lt;span style="color:#f92672"&gt;-&lt;/span&gt;til_development&lt;span style="color:#f92672"&gt;=#&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;where&lt;/span&gt; array_length(slack_notified_at_likes_threshold, &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;) &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; title
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;-------------------------------------------
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Because Javascript
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Percent Notation
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; DIY Grids &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; Designing UI &lt;span style="color:#66d9ef"&gt;in&lt;/span&gt; Illustrator
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;rows&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When the dimension is &lt;code&gt;1&lt;/code&gt;, a more terse solution is &lt;code&gt;cardinality&lt;/code&gt;:&lt;/p&gt;</description></item><item><title>PostgreSQL Empty Array as Default Value</title><link>https://jakeworth.com/tils/default-to-empty-array-in-postgres/</link><pubDate>Sun, 14 Feb 2016 15:46:54 -0600</pubDate><guid>https://jakeworth.com/tils/default-to-empty-array-in-postgres/</guid><description>&lt;p&gt;We can add a PostgreSQL array column with a default empty array using:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;add&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;column&lt;/span&gt; things integer[] &lt;span style="color:#66d9ef"&gt;not&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;null&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;default&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;{}&amp;#39;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Cleanup PostgreSQL Databases</title><link>https://jakeworth.com/tils/cleanup-postgres-databases/</link><pubDate>Mon, 02 Nov 2015 16:36:56 -0600</pubDate><guid>https://jakeworth.com/tils/cleanup-postgres-databases/</guid><description>&lt;p&gt;Today I learned that I have thirty-nine Postgres databases on my computer, after running this command inside psql:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;\l ;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Each one is small, but I don&amp;rsquo;t like to carrying around old data. I ended up dropping nine of them, with:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;drop database foo_development;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a lighter storage and cognitive load.&lt;/p&gt;</description></item><item><title>Postgres Unlogged</title><link>https://jakeworth.com/tils/postgres-unlogged/</link><pubDate>Wed, 23 Sep 2015 07:37:27 -0500</pubDate><guid>https://jakeworth.com/tils/postgres-unlogged/</guid><description>&lt;p&gt;Using a Postgres table for caching? You might want to try making it &lt;code&gt;unlogged&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;unlogged&lt;/code&gt; tables are not written to the write-ahead log, which makes them much faster. This also means they are not crash-safe, and are truncated when a crash or unclean shutdown occurs. For caching purposes, that&amp;rsquo;s likely to be an acceptable tradeoff.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.postgresql.org/docs/current/static/sql-createtable.html"&gt;Documentation&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Prepare / Execute</title><link>https://jakeworth.com/tils/prepare-execute/</link><pubDate>Tue, 08 Sep 2015 18:51:01 -0500</pubDate><guid>https://jakeworth.com/tils/prepare-execute/</guid><description>&lt;p&gt;You can store a PostgreSQL query with &lt;code&gt;prepare&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;db=# prepare posts_search as select title from posts limit 5;
PREPARE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Call the method with &lt;code&gt;execute&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;db=# execute posts_search;
title
-----------------------------------
Hello World!
My First Pull Request: HAML
My First Pull Request: Sinatra
My First Pull Request: Capistrano
My First Pull Request: SASS
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deallocate the query with &lt;code&gt;deallocate&lt;/code&gt;, and you can set it again.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;db=# deallocate posts_search;
DEALLOCATE
db=# prepare posts_search as select title from posts limit 10;
PREPARE
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Psql Connect</title><link>https://jakeworth.com/tils/psql-connect/</link><pubDate>Tue, 08 Sep 2015 18:51:01 -0500</pubDate><guid>https://jakeworth.com/tils/psql-connect/</guid><description>&lt;p&gt;Want to change database connections from inside psql? You can!&lt;/p&gt;
&lt;p&gt;Psql, the REPL for Postgres, has a useful meta-command called &lt;code&gt;\connect&lt;/code&gt;, or &lt;code&gt;\c&lt;/code&gt;. This lets you establish a new connection to a Postgres server, while closing the current connection.&lt;/p&gt;
&lt;p&gt;Here is the required format:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;\c or \connect [ dbname [ username ] [ host ] [ port ] ] | conninfo
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Only &lt;code&gt;\c [my_database]&lt;/code&gt; is required; omitted parameters are taken from the previous connection.&lt;/p&gt;</description></item><item><title>Terminate Database Connections</title><link>https://jakeworth.com/tils/terminate_database_connections/</link><pubDate>Tue, 08 Sep 2015 18:51:01 -0500</pubDate><guid>https://jakeworth.com/tils/terminate_database_connections/</guid><description>&lt;p&gt;To maintain data integrity, certain actions like &lt;code&gt;rake db:drop&lt;/code&gt; will not execute when there are active sessions on a Postgres database. You&amp;rsquo;ll get an error like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;ERROR: database &amp;#34;database_name&amp;#34; is being accessed by other users
DETAIL: There are 2 other session(s) using the database.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Sessions can be killed from the command line, but a safer route is to kill them with a database method. First, revoke all public access from the database:&lt;/p&gt;</description></item></channel></rss>