UJP - 技術情報1

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

PostgreSQLでPL/PGSQLを使えるようにしてHelloWorld

PostgreSQLでPL/PGSQLを使えるようにしてHelloWorld


0.改訂履歴

  • 2005.10.18 新規作成

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してみる.

  • psqlで接続する.
[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=>  
  • 終了.


広告スペース
Google