PostgreSQLのLEFTを試す

今日もSQLZOOでSQLを学んだ。 sqlzoo.net


開発環境

github.com

$ docker exec -it faaaar-db bash

root@{CONTAINER_ID}:/# psql -U postgres

postgres=# \dt
           List of relations
 Schema |   Name    | Type  |  Owner   
--------+-----------+-------+----------
 public | idol      | table | postgres
 public | idol_unit | table | postgres
 public | unit      | table | postgres

LEFT

nameの前から1文字目までを抽出。

SELECT
    name,
    LEFT(name, 1)
FROM
    idol
;

    name     | left 
-------------+------
 櫻木 真乃   | 櫻
 八宮 めぐる | 八
 風野 灯織   | 風
 月岡 恋鐘   | 月
 幽谷 霧子   | 幽

応用系が思いつかなかったので今日はここまで。

参考