<?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 Yang's Blog</title><link>https://blog.yangtheman.com/tags/postgres/</link><description>Recent content in Postgres on Yang's Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>© 2026 Yang Chung</copyright><lastBuildDate>Thu, 22 Oct 2009 07:48:03 +0000</lastBuildDate><atom:link href="https://blog.yangtheman.com/tags/postgres/index.xml" rel="self" type="application/rss+xml"/><item><title>Counting rows and modifying MySQL to work with Postgres or Heroku</title><link>https://blog.yangtheman.com/2009/10/22/counting-rows-and-modifying-mysql-to-work-with-postgres-or-heroku/</link><pubDate>Thu, 22 Oct 2009 07:48:03 +0000</pubDate><guid>https://blog.yangtheman.com/2009/10/22/counting-rows-and-modifying-mysql-to-work-with-postgres-or-heroku/</guid><description>&lt;p&gt;Now I am moving on to Open Translation Project. I&amp;rsquo;ve done some translation work before, including one of Paul Graham&amp;rsquo;s essay - &lt;a href="http://www.paulgraham.com/notnot.html" target="_blank" rel="noreferrer"&gt;Why to not not start a startup&lt;/a&gt;. BTW, he finally made a link from the essay to my translation. I used Google Translate as base, but I couldn&amp;rsquo;t believe how bad the translation was. Yahoo&amp;rsquo;s Babel Fish was a little better, but not as much. That&amp;rsquo;s where I got the idea of creating this possibly massive project.&lt;/p&gt;
&lt;p&gt;Anyhow, I wanted to find a way of selecting an article or blog that was translated the most. I had one model that stored basic information of original article/blog. Then its children are translations. So, I need to count rows of children with the same parent. In MySQL, I had the following statement in Rails.&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;@top_origs = OrigPost.find(:all,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;                              :select =&amp;gt; &amp;#39;orig_posts.*, count(posts.id) as post_count&amp;#39;,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;                              :joins =&amp;gt; &amp;#39;left outer join posts on posts.orig_post_id = orig_posts.id&amp;#39;,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;                              :group =&amp;gt; &amp;#39;orig_posts.id&amp;#39;,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;                              :order =&amp;gt; &amp;#39;post_count DESC&amp;#39;,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;                              :limit =&amp;gt; 5)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</description></item></channel></rss>