PostgreSQLでPL/PGSQLを使えるようにしてHelloWorld
PostgreSQLでPL/PGSQLを使えるようにしてHelloWorld
0.改訂履歴
1.はじめに
このドキュメントでは,PosgreSQLでPL/PGSQLを使える様にする手順を説明する. createlangコマンドにて,plpgsqlをインストールし,簡単な関数をcreate function後,テスト用にHello,Worldを表示させてみる事で稼働確認する.
2.createlangする.
- データベースでPL/PGSQLを利用できるようにするには,os上でcreatelangコマンドを実行する.
[postgres@juno postgres]$ createlang plpgsql MyTestDB
[postgres@juno postgres]$
|
3.Hello worldしてみる.
[postgres@juno postgres]$ psql -U posggres MyTestDB
Welcome to psql 7.4.6, the PostgreSQL interactive terminal.
Type: ¥copyright for distribution terms
¥h for help with SQL commands
¥? for help on internal slash commands
¥g or terminate with semicolon to execute query
¥q to quit
MyTestDB=>
|
- Hello worldを表示するだけの,関数を作成する.
MyTestDB=> create function helloworld() returns text
MyTestDB-> as ' begin return ''hello,world''; end; '
MyTestDB-> language 'plpgsql';
CREATE FUNCTION
MyTestDB=>
|
- createされた.
- 関数のリストを取得して確認する.
MyTestDB=> ¥df helloworld
List of functions
Result data type | Schema | Name | Argument data types
------------------+--------+------------+---------------------
text | public | helloworld |
(1 row)
MyTestDB=>
|
MyTestDB=> select helloworld();
helloworld
-------------
hello,world
(1 row)
MyTestDB=>
|
MyTestDB=> drop function helloworld();
DROP FUNCTION
MyTestDB=>
|