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
NOT VALIDな検査制約 / check constraint that is not v...
Search
Yasuo Honda
December 20, 2024
Technology
300
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
NOT VALIDな検査制約 / check constraint that is not valid
https://pgunconf.connpass.com/event/338511/
Yasuo Honda
December 20, 2024
More Decks by Yasuo Honda
See All by Yasuo Honda
PostgreSQL 18のNOT ENFORCEDな制約とDEFERRABLEの関係
yahonda
1
310
私のRails開発環境
yahonda
0
240
Railsの話をしよう
yahonda
0
280
RailsのPostgreSQL 18対応
yahonda
0
3.5k
Contributing to Rails? Start with the Gems You Already Use
yahonda
2
250
PostgreSQL 18 cancel request key長の変更とRailsへの関連
yahonda
0
320
extensionとschema
yahonda
1
360
今、始める、第一歩。 / Your first step
yahonda
3
1.5k
RailsのPull requestsのレビューの時に私が考えていること
yahonda
11
8.5k
Other Decks in Technology
See All in Technology
Docker Desktop不要の時代が来る? WSL標準の「wslc」で Linuxコンテナを動かしてみた.
ueponx
0
520
AI・ロボティクスと自動化社会 / AI, Robotics, and the Automated Society
ks91
PRO
0
140
金融の未来を考える / Thinking About the Future of Finance
ks91
PRO
0
110
なぜ人は自分のプロジェクトを 「なんちゃってアジャイル」と 自嘲するのか
kozotaira
0
230
Terraform 101 (初心者向け) 資料
shuadachi
0
160
“詰む”前に仕組みを作れ 〜技術の波に溺れないためのキャッチアップ術〜
takasyou
8
5k
製造現場での生成AIの活用、およびエージェントAIの実装のあり方、AVEVAの取り組み
iotcomjpadmin
0
210
Hatena Engineer Seminar 37 jj1uzh
jj1uzh
0
410
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
220
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
840
本当の”仕事”を手放せる未来が見えた
mu7889yoon
0
210
從觀望到全公司落地:AI Agentic Coding 導入實戰 — 流程整合與安全治理
appleboy
1
510
Featured
See All Featured
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
The Limits of Empathy - UXLibs8
cassininazir
1
380
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How to build a perfect <img>
jonoalderson
1
5.8k
Deep Space Network (abreviated)
tonyrice
0
220
How to Ace a Technical Interview
jacobian
281
24k
Technical Leadership for Architectural Decision Making
baasie
3
430
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.9k
Color Theory Basics | Prateek | Gurzu
gurzu
0
380
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
580
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
480
Everyday Curiosity
cassininazir
0
250
Transcript
第50回 PostgreSQLアンカンファレンス@オンライン Yasuo Honda @yahonda NOT VALIDな検査制約
• Yasuo Honda @yahonda ◦ Rails committer ◦ 第46回 PostgreSQLアンカンファレンス
以来4回目の参加です ▪ PostgreSQL 15とRailsと - Speaker Deck ▪ 遅延可能な一意性制約 - Speaker Deck ▪ pg_stat_statementsで inの数が違うSQLをまとめて ほしい - Speaker Deck 自己紹介
• Ruby on Railsのmigration DSLで検査制約を作る2つの方法 ◦ テーブル作成後に、`add_check_constraint`で作成 ◦ テーブル作成時に`t.check_constraint`で作成 •
いずれも`:validate` 引数を設定可能(デフォルトはtrue) ◦ falseを渡すと、無効な検査制約として作成される意図(NOT VALID) だった意図通りは`add_check_constraint`のみ ◦ https://api.rubyonrails.org/classes/ActiveRecord/Connecti onAdapters/SchemaStatements.html#method-i-add_chec k_constraint 背景
• add_check_constraint ◦ CREATE TABLE "posts" ("id" bigserial primary key,
"title" character varying); ◦ ALTER TABLE "posts" ADD CONSTRAINT posts_const CHECK (char_length(title) >= 5) NOT VALID; • check_constraint ◦ CREATE TABLE "comments" ("id" bigserial primary key, "body" text, CONSTRAINT comments_const CHECK (char_length(body) >= 5) NOT VALID); 発行されていた SQL https://gist.github.com/yahonda/7e61f3f71 681cfa03111fed55714b0b4
• alter tableで別に作成した方は意図どおり、not valid • create table内で作成した方は、意図に反してvalid • リンク 作成された検査制約の状態
• 検査制約のNOT VALIDをalter tableのみで追加できるのは意図した振 る舞いのよう(フォント赤字は筆者) • https://www.postgresql.org/docs/current/sql-altertable.html ◦ > This
form adds a new constraint to a table using the same constraint syntax as CREATE TABLE, plus the option NOT VALID, which is currently only allowed for foreign key and CHECK constraints. • https://www.postgresql.org/docs/9.2/release-9-2.html で追加 解釈
• create table時にnot validオプションはエラーになって欲しい • 関連する議論 ◦ https://www.postgresql.org/message-id/CAEZATCX8u8GU -M_DFtjksRUQhwm8zur3BQvLamFUX8MwYNntPg%40mail. gmail.com
• Rails側での追加対応も考えたい(今日のトピック外) 疑問
• PostgreSQL 18 devel(資料作成時のmasterブランチ) ◦ https://github.com/postgres/postgres/commit/39240bcad 56dc51a7896d04a1e066efcf988b58f • Rails main
◦ https://github.com/rails/rails/commit/3a91006d22fa465fb ce41370bbe66aa332bdcc2d • Red Hat Enterprise Linux release 9.5 (Plow) 環境
• https://github.com/rails/rails/pull/40192 • https://github.com/rails/rails/issues/53732 • https://github.com/rails/rails/pull/53735 • https://www.postgresql.org/docs/current/catalog-pg-constrai nt.html •
https://www.postgresql.org/message-id/E1QcJd3-0001HT-91% 40gemulon.postgresql.org • https://github.com/postgres/postgres/commit/897795240cfaa ed724af2f53ed2c50c9862f951f • 参照
• pgsql-hackersにて2024年12月5日から下記の議論が始まっていること を教えていただきました ◦ https://www.postgresql.org/message-id/CACJufxEQcHNh
[email protected]
ail.com ◦ 内容確認してreplyしてみます 発表後の補足
おわり
おわり