SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
PL/Perlのはなし
(LT)
@syachi
Hokkaido.pm Casual#13
テーマ「モダンModule入門」
2013-05-15
Perlで書かれたモジュールを
PostgreSQLから呼ぶ
PL/Perlのはなし
いわゆるストアドプロシージャ
PostgreSQL上でPerlが動くよ
QuickStart
testdb=# CREATE LANGUAGE plperl;
CREATE LANGUAGE
testdb=# CREATE OR REPLACE FUNCTION perl_set_int(int)
testdb-# RETURNS SETOF INTEGER AS $$
testdb$# foreach (0..$_[0]) {
testdb$# return_next($_);
testdb$# }
testdb$# return undef;
testdb$# $$ LANGUAGE plperl;
結果
testdb=# select perl_set_int(5);
perl_set_int
--------------
0
1
2
3
4
5
(6 rows)
超モダン
:p
plperl は
useが使えなかったり
サーバ上のファイルが見れなかったり
制限付きで安全
そんな制限が不要の方は
plperluを使います。
CREATE LANGUAGE plperlu;
例
Acme::MorningMusume の
メンバー一覧を返してみる
testdb=# CREATE TYPE musumetype AS (
testdb-# name_ja text, age integer, hometown text, class integer);
testdb=# CREATE OR REPLACE FUNCTION musumetachi()
testdb-# RETURNS SETOF musumetype AS $$
testdb$# use strict;
testdb$# use utf8;
testdb$# use Encode;
testdb$# use Acme::MorningMusume;
testdb$# foreach (Acme::MorningMusume->new->members()) {
testdb$# return_next({
testdb$# name_ja => Encode::decode_utf8($_->name_ja),
testdb$# age => Encode::decode_utf8($_->age),
testdb$# hometown => Encode::decode_utf8($_->hometown),
testdb$# class => Encode::decode_utf8($_->class),
testdb$# });
testdb$# }
testdb$# return undef;
testdb$# $$ LANGUAGE plperlu;
CREATE FUNCTION
testdb=#	
 SELECT	
 *	
 FROM	
 musumetachi()	
 ORDER	
 BY	
 age	
 DESC;
	
 	
 name_ja	
 	
 	
 |	
 age	
 |	
 	
 hometown	
 	
 |	
 class
------------+-----+------------+-------
	
 中澤裕子	
 	
 	
 |	
 	
 39	
 |	
 京都府	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 1
	
 石黒彩	
 	
 	
 	
 	
 |	
 	
 35	
 |	
 北海道	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 1
	
 保田圭	
 	
 	
 	
 	
 |	
 	
 32	
 |	
 千葉県	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 2
	
 飯田圭織	
 	
 	
 |	
 	
 31	
 |	
 北海道	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 1
	
 安倍なつみ	
 |	
 	
 31	
 |	
 北海道	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 1
	
 市井紗耶香	
 |	
 	
 29	
 |	
 千葉県	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 2
	
 矢口真里	
 	
 	
 |	
 	
 29	
 |	
 神奈川県	
 	
 	
 |	
 	
 	
 	
 	
 2
	
 吉澤ひとみ	
 |	
 	
 28	
 |	
 埼玉県	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 4
	
 福田明日香	
 |	
 	
 28	
 |	
 東京都	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 1
	
 石川梨華	
 	
 	
 |	
 	
 27	
 |	
 神奈川県	
 	
 	
 |	
 	
 	
 	
 	
 4
	
 藤本美貴	
 	
 	
 |	
 	
 27	
 |	
 北海道	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 6
	
 後藤真希	
 	
 	
 |	
 	
 27	
 |	
 東京都	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 3
	
 高橋愛	
 	
 	
 	
 	
 |	
 	
 26	
 |	
 福井県	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 5
	
 紺野あさ美	
 |	
 	
 26	
 |	
 北海道	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 5
	
 加護亜依	
 	
 	
 |	
 	
 25	
 |	
 奈良県	
 	
 	
 	
 	
 |	
 	
 	
 	
 	
 4
....略
結果
Have fun !!

Weitere ähnliche Inhalte

Empfohlen

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

PL/Perlのはなし