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
0
290
many-many-select-PostgreSQL-conference-2021-japan
Lightning talk material presented at "PostgreSQL Conference 2021 Japan".
nuko_yokohama
November 12, 2021
Tweet
Share
More Decks by nuko_yokohama
See All by nuko_yokohama
BRIN(Block Range INdex)
nuko_yokohama
1
370
ltree extension
nuko_yokohama
1
450
PostgreSQL Built in Sharding
nuko_yokohama
0
710
PostgreSQL 16 Support load balancing in libpq
nuko_yokohama
0
460
PostgreSQL 16 Add pg_stat_io view, providing more detailed IO statistics
nuko_yokohama
0
210
Do PostgreSQL 16 Dream of Multi-Master Replication?
nuko_yokohama
0
1.2k
Performance_loss_due_to_data_file_extend
nuko_yokohama
0
260
Apache AGE
nuko_yokohama
0
390
psql, my favorite tool!
nuko_yokohama
1
490
Other Decks in Technology
See All in Technology
Microsoft Build 2025 技術/製品動向 for Microsoft Startup Tech Community
torumakabe
2
220
ひとり情シスなCTOがLLMと始めるオペレーション最適化 / CTO's LLM-Powered Ops
yamitzky
0
390
AWS CDK 実践的アプローチ N選 / aws-cdk-practical-approaches
gotok365
4
550
PHP開発者のためのSOLID原則再入門 #phpcon / PHP Conference Japan 2025
shogogg
2
470
Liquid Glass革新とSwiftUI/UIKit進化
fumiyasac0921
0
150
Oracle Audit Vault and Database Firewall 20 概要
oracle4engineer
PRO
3
1.7k
キャディでのApache Iceberg, Trino採用事例 -Apache Iceberg and Trino Usecase in CADDi--
caddi_eng
0
180
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
29
9.5k
BrainPadプログラミングコンテスト記念LT会2025_社内イベント&問題解説
brainpadpr
0
160
Claude Code Actionを使ったコード品質改善の取り組み
potix2
PRO
4
1.8k
SalesforceArchitectGroupOsaka#20_CNX'25_Report
atomica7sei
0
100
初めてのAzure FunctionsをClaude Codeで作ってみた / My first Azure Functions using Claude Code
hideakiaoyagi
1
190
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
14k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Building Adaptive Systems
keathley
43
2.6k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Documentation Writing (for coders)
carmenintech
71
4.9k
Designing for humans not robots
tammielis
253
25k
How STYLIGHT went responsive
nonsquared
100
5.6k
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 が使えるようになったの で使ってみよう なるほど?
おわり