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
nuko_yokohama
November 12, 2021
Technology
330
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
51
PostgreSQL 18 is coming soon!
nuko_yokohama
0
300
BRIN(Block Range INdex)
nuko_yokohama
1
490
ltree extension
nuko_yokohama
1
830
PostgreSQL Built in Sharding
nuko_yokohama
0
810
PostgreSQL 16 Support load balancing in libpq
nuko_yokohama
0
540
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
Terraformモジュールは、なぜ「魔境」化するのか
hayama17
2
220
AI-DLCを活用した高品質・安全なAI駆動開発実践 / AI Driven Development with AI-DLC
yoshidashingo
0
150
価格.comをAI駆動で全面刷新する ー 30年分の技術的負債を返し、次の30年の土台をつくる ー / AI Engineering Summit Tokyo 2026
tkyowa
50
56k
個人最適 から 全体最適 へ AI情報共有会・AIギルド・AI-DLC で進める カンリーの組織展開
rfdnxbro
0
1.9k
GoとSIMDとWasmの今。
askua
3
510
Platform engineering for developers, architects & the rest of us (AI agents)
danielbryantuk
0
190
Agentic Defenseとともにセキュリティエンジニアが輝き続けるには / How Security Engineers Can Keep Excelling with Agentic Defense
yuj1osm
0
120
DevOps Agentで始めるAWS運用 〜フロンティアエージェントが変える運用の現場〜
nyankotaro
1
320
AI フレンドリーなエラー監視を TypeScript で実現する
shinyaigeek
2
270
AI Engineering Summit Tokyo 2026 AIの前に、やることがある 〜医療データ企業の4フェーズ〜
dtaniwaki
0
2.2k
Diagnosing performance problems without the guesswork
elenatanasoiu
0
170
LLMと共に進化するプロセスを目指して
ymatsuwitter
12
3.6k
Featured
See All Featured
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
Embracing the Ebb and Flow
colly
88
5.1k
So, you think you're a good person
axbom
PRO
2
2.1k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
380
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
380
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
The Pragmatic Product Professional
lauravandoore
37
7.3k
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 が使えるようになったの で使ってみよう なるほど?
おわり