Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
many-many-select-PostgreSQL-conference-2021-japan
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
nuko_yokohama
November 12, 2021
Technology
340
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
many-many-select-PostgreSQL-conference-2021-japan
Lightning talk material presented at "PostgreSQL Conference 2021 Japan".
nuko_yokohama
November 12, 2021
More Decks by nuko_yokohama
See All by nuko_yokohama
PostgreSQL ECPG
nuko_yokohama
0
67
PostgreSQL 18 is coming soon!
nuko_yokohama
0
350
BRIN(Block Range INdex)
nuko_yokohama
1
520
ltree extension
nuko_yokohama
1
860
PostgreSQL Built in Sharding
nuko_yokohama
0
830
PostgreSQL 16 Support load balancing in libpq
nuko_yokohama
0
570
PostgreSQL 16 Add pg_stat_io view, providing more detailed IO statistics
nuko_yokohama
0
290
Do PostgreSQL 16 Dream of Multi-Master Replication?
nuko_yokohama
0
1.4k
Performance_loss_due_to_data_file_extend
nuko_yokohama
0
320
Other Decks in Technology
See All in Technology
AWS ネットワーク構築でハマった(ハマりかけた) 5選とそこから得た教訓
nagisa53
4
270
案件に一番詳しいAIを Amazon Bedrock AgentCore で作る ― 知見が知見を生むチームへ / Compounding Knowledge with AgentCore
yusukeshimizu
1
150
カートの信頼性を担保するWireMockを使ったe2eテスト
ykagano
0
530
20分でわかるセキュアAPI
nwiizo
2
310
【CEDEC2026】Creative Approaches to Localizing the Dialects and Unique Speech of Umamusume: Pretty Derby Characters in English
cygames
PRO
3
25k
強化学習「理論」入門
enakai00
3
3.6k
AIのためのEthernet技術動向 (SerDes)
markunet
1
220
FORENSIA: ローカルLLMフォレンジックハーネス
sumeshi
2
420
システム思考で問題に対処する
yussak
0
340
小粒でもパワフルなJS Runtime Antjsについて
comamoca
0
100
Service Connect 上のサービスに ECS Service の外側から到達できなかった話
ota1022
1
270
事業価値と Engineering 2026年度版
recruitengineers
PRO
51
25k
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
250
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
420
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
Skip the Path - Find Your Career Trail
mkilby
1
190
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
650
So, you think you're a good person
axbom
PRO
2
2.1k
Ruling the World: When Life Gets Gamed
codingconduct
0
300
YesSQL, Process and Tooling at Scale
rocio
174
15k
Being A Developer After 40
akosma
91
590k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
580
Transcript
メニー・メニー・セレクト PostgresSQL Conference 2021 (2021-11-12) Lightning Talk
自己紹介 • ぬこ@横浜 (@nuko_yokohama) • にゃーん • 趣味でポスグレをやってる者だ • SELECT
なんもわからん
この発表から得られるもの • このレーダーチャートから察してください。 即応性 汎用性 持続性 ぬこ性 実用性 0 5
安定の ぬこクオリティ
今日のお題 SELECT だらけの SELECT
こんな SELECT 文をみかけた • ある日、 PostgreSQL 14 上で動作する こんな SELECT
文をみかけた select=# select "select"."select"::"select" select, "select.select"."select"::"select" select FROM "select"."select" "select" JOIN " select.select " "select.select" ON ("select"."select"::"select" = "select.select".select::"select") ; select | select --------+-------- select | select (1 row) select=#
このクエリを作ったのは誰だぁ! わたしです
どんだけ select あるねん • こんな短い SELECT 文の中に 25 個の” select”
が含まれている。 • おまけ:データベース名も select です。 select=# select "select"."select"."select"::"select" select, "select.select"."select"::"select" select FROM "select"."select" "select" JOIN " select.select " "select.select" ON ("select"."select"::"select" = "select.select".select::"select") ; select | select --------+-------- select | select (1 row) select=#
こんな環境で実行した • “select” ENUM data type select=# \dT+ select List
of data types Schema | Name | Internal name | Size | Elements | Owner | Access privileges | Description --------+----------+---------------+------+----------+----------+-------------------+------------- public | "select" | select | 4 | select +| postgres | | | | | | "select"+| | | | | | | 'select' | | | (1 row)
こんな環境で実行した • “select” table on “select” schema • “select” column
in “select” table select=# \dn List of schemas Name | Owner --------+---------- public | postgres select | postgres (2 rows) select=# \d "select"."select" Table "select.select" Column | Type | Collation | Nullable | Default --------+----------+-----------+----------+--------- select | "select" | | | select=#
こんな環境で実行した • “ select.select ” table on public schema •
“select” column in “select” table select=# \d public." select.select " Table "public. select.select " Column | Type | Collation | Nullable | Default --------+----------+-----------+----------+--------- select | "select" | | | select=# 自力では入力できないけど、 psql の TAB 補完はサジェストしてくれる
どういうことかというと • SELECT statement command tag select=# select "select"."select"."select"::"select" select,
"select.select"."select"::"select" select FROM "select"."select" "select" JOIN " select.select " "select.select" ON ("select"."select"::"select" = "select.select".select::"select") ; select | select --------+-------- select | select (1 row) select=#
どういうことかというと • “select” スキーマの” select” 表をエイリアス” select” にする。 • ”select”
列を” select” 型でキャスト • ラベル select を付与( PostgreSQL 14 ~ ) select=# select "select"."select"."select"::"select" select, "select.select"."select"::"select" select FROM "select"."select" "select" JOIN " select.select " "select.select" ON ("select"."select"::"select" = "select.select".select::"select") ; select | select --------+-------- select | select (1 row) select=# エイリアス “ select” を定義
どういうことかというと • public スキーマの” < 改行 >select.select< 改行 >” 表の
エイリアス” select.select”.”select” 列を” select” 型でキャスト • ラベル select を付与( PostgreSQL 14 ~ ) • select=# select "select"."select"."select"::"select" select, "select.select"."select"::"select" select FROM "select"."select" "select" JOIN " select.select " "select.select" ON ("select"."select"::"select" = "select.select".select::"select") ; select | select --------+-------- select | select (1 row) select=#
どういうことかというと • ”.select” エイリアスの” select” 列を” select” 型でキャスト • ”select.select”
エイリアスの” select” 列を” select” 型でキャスト • それを = 比較 select=# select "select"."select"."select"::"select" select, "select.select"."select"::"select" select FROM "select"."select" "select" JOIN " select.select " "select.select" ON ("select"."select"::"select" = "select.select".select::"select") ; select | select --------+-------- select | select (1 row) select=#
まとめ • わかりにくいクエリのコツ – ユーザ定義型に” select” とか使ってみよう – オブジェクト名(スキーマ名、テーブル名、列名)に” select”
とか使ってみよう – オブジェクト名に改行を含めると混乱しやすくて楽しいぞ – PostgreSQL 14 から列ラベルに (AS なし ) で select が使えるようになったの で使ってみよう なるほど?
おわり