Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
many-many-select-PostgreSQL-conference-2021-japan
Search
nuko_yokohama
November 12, 2021
Technology
350
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
69
PostgreSQL 18 is coming soon!
nuko_yokohama
0
460
BRIN(Block Range INdex)
nuko_yokohama
1
540
ltree extension
nuko_yokohama
1
880
PostgreSQL Built in Sharding
nuko_yokohama
0
840
PostgreSQL 16 Support load balancing in libpq
nuko_yokohama
0
580
PostgreSQL 16 Add pg_stat_io view, providing more detailed IO statistics
nuko_yokohama
0
300
Do PostgreSQL 16 Dream of Multi-Master Replication?
nuko_yokohama
0
1.4k
Performance_loss_due_to_data_file_extend
nuko_yokohama
0
340
Other Decks in Technology
See All in Technology
20260930_Gemma4_Hands-on
tsho
0
220
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
4
970
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
210
ログラスのマルチプロダクトを 支える認証基盤 〜テナントごとに異なる統制とどう向き合うか〜
dada4386
3
400
AI Made Us Faster at Solving the Wrong Problems
marceloancelmo
0
160
雪かき部 #7 もう怖くない!SELECT文!
foursue
0
280
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
350
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
150
自主式軟體工廠
philipz
0
220
IoTデバイスを繋げるプロトコルMatterをAndroidで使用する方法
harutiro
0
120
BedrockとLambdaで作る リアルタイム進行型推理ゲーム
kawametho
0
190
Futexes the good, the bad, the ugly
ennael
PRO
0
120
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
550
Building Flexible Design Systems
yeseniaperezcruz
330
41k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
340
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Skip the Path - Find Your Career Trail
mkilby
1
240
How to build a perfect <img>
jonoalderson
1
6.1k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
440
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
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 が使えるようになったの で使ってみよう なるほど?
おわり