<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>ingnis</author_name>
  <author_url>https://blog.hatena.ne.jp/ingnis/</author_url>
  <blog_title>インゲージ開発者ブログ</blog_title>
  <blog_url>https://blog.ingage.jp/</blog_url>
  <categories>
    <anon>バックエンド</anon>
  </categories>
  <description>どうも、にしむらです。今回はRails5.2 PostgreSQLの話です。 messages テーブル に 文字型 str_id に数字が0埋めなしで保存されている場合は以下のようにソートされます。 select * from messages order by str_id; id | str_id ----+------- 50 | 1000 47 | 110 46 | 12 この場合、lpadを使って0埋めの文字列に変換することで正しく並び替えることができます。 lpad(str_id, 5, '0') str_id を 5桁の数字にして桁が足りない場合は左端から 0 で埋める sel…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.ingage.jp%2Fentry%2F2022%2F04%2F19%2F173218&quot; title=&quot;0埋めされていない数字文字列をソートしたい - インゲージ開発者ブログ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2022-04-19 17:32:18</published>
  <title>0埋めされていない数字文字列をソートしたい</title>
  <type>rich</type>
  <url>https://blog.ingage.jp/entry/2022/04/19/173218</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
