Upgrade to Pro — share decks privately, control downloads, hide ads and more …

アプリの実装に役立つBackendとしてのPostgreSQL

 アプリの実装に役立つBackendとしてのPostgreSQL

2019-01-20 の 岡山モバイルアプリ開発もくもく会 での発表資料です。

Takahashi Ikki

January 20, 2019
Tweet

More Decks by Takahashi Ikki

Other Decks in Programming

Transcript

  1. ഑ྻܕͷྫ INSERT INTO blogs (title, content, tags) VALUES ('΋͘΋͘ձ', '໌೔͸΋͘΋͘ձͰ͢',

    '{ "ios", "android" , "PostgreSQL" }') title | contents | tags ------------+----------------------+-------------------------- ΋͘΋͘ձ | ໌೔͸΋͘΋͘ձͰ͢ | {ios,android,PostgreSQL} (1 row)
  2. ഑ྻܕͷݕࡧʹ͍ͭͯ 'ios' λά͕͋Δ΋ͷΛݕࡧ. SELECT * FROM blogs WHERE 'ios' =

    ANY(tags); title | contents | tags ------------+----------------------+-------------------------- ΋͘΋͘ձ | ໌೔͸΋͘΋͘ձͰ͢ | {ios,android,PostgreSQL} (1 row) ios λά ͕͍ͭͯΔ ͔ͭ android λά͕͍ͭͯΔ Έ͍ͨͳݕࡧ΋Ͱ͖Δɻ
  3. ഑ྻܕͷऔಘʹ͍ͭͯ SELECT tags[1] AS tag FROM blogs; tag ---------- ios

    (1 row) ͦͷ΄͔ʹ΋ tags[2:3] : ഑ྻͷ 2ʙ3൪໨Λऔಘ tags[2:] : ഑ྻͷ 2൪໨Ҏ߱Λऔಘ tags[:2] : ഑ྻͷ 2൪໨ҎԼΛऔಘ ※ 0͔Β։࢝͠ͳ͍ࣄʹதࢭ
  4. ͦͷଞʹ΋ָʹཁ݅Λ ຬͨͤΔ SELECT unnest(tags) , count(*) FROM blogs GROUP BY

    unnest(tags) ORDER BY count(*) DESC; unnest | count ------------+------- database | 2 ios | 1 PostgreSQL | 1 android | 1 (4 rows)
  5. 4. ࠂ஌ தࠃ஍ํDBษڧձ 2019-02-02 (౔) ୈ26ճ தࠃ஍ํDBษڧձ in Ԭࢁ https://dbstudychugoku.connpass.com/event/112468/

    SQLνϡʔχϯά(EXPLAIN)ͷํ๏΍ύϥϝʔλνϡʔχϯάΛ औΓ্͛·͢ɻ ઈࢍLTൃදऀΛืूதͰ͢ʂʂ