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
61
PostgreSQL 18 is coming soon!
nuko_yokohama
0
310
BRIN(Block Range INdex)
nuko_yokohama
1
510
ltree extension
nuko_yokohama
1
840
PostgreSQL Built in Sharding
nuko_yokohama
0
820
PostgreSQL 16 Support load balancing in libpq
nuko_yokohama
0
550
PostgreSQL 16 Add pg_stat_io view, providing more detailed IO statistics
nuko_yokohama
0
270
Do PostgreSQL 16 Dream of Multi-Master Replication?
nuko_yokohama
0
1.4k
Performance_loss_due_to_data_file_extend
nuko_yokohama
0
310
Other Decks in Technology
See All in Technology
Fabricをフル活用する AI Agent Hub -製造業特化AIエージェントの設計
iotcomjpadmin
0
190
ご挨拶「10周年を迎える共創ラボのこれまでとこれから」
iotcomjpadmin
0
180
飲食店もAIで。レジ締めやハンディシステムをつくってる話 / Using AI for restaurant management
vtryo
0
230
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
180
最近評価が難しくなった
maroon8021
0
130
認証認可だけじゃない! ID管理の構成要素と ライフサイクルを意識しよう
ritou
1
450
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
250
デジタル・デザイン:次の50年を描く「進化する青写真」
y150saya
0
800
Tech-Verse 2026_Keynote
lycorptech_jp
PRO
0
130
CVE-2026-20833_脆弱性対応とAES 化について
jukishiya
0
350
初めてのDatabricks勉強会
taka_aki
2
230
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
230
Featured
See All Featured
Information Architects: The Missing Link in Design Systems
soysaucechin
0
990
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
240
Navigating Weather and Climate Data
rabernat
0
270
Scaling GitHub
holman
464
140k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
The Invisible Side of Design
smashingmag
301
52k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Designing Powerful Visuals for Engaging Learning
tmiket
1
430
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
55k
Side Projects
sachag
455
43k
Building AI with AI
inesmontani
PRO
1
1.1k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
380
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 が使えるようになったの で使ってみよう なるほど?
おわり