Slide 12
Slide 12 text
Copyright ©Unique Vision Company, All Rights Reserved.
12
PL/pgSQLとは
任意の型の定義
また任意の型が定義できます。例えば 2つのテーブルを結合したような型を定義して FUNCTIONの戻り値に設
定できます。
DROP TYPE IF EXISTS type_project_get_select_users CASCADE;
CREATE TYPE type_project_get_select_users AS (
uuid UUID,
name TEXT
company_name TEXT
);
CREATE OR REPLACE FUNCTION project_get_select_users(
) RETURNS SETOF type_project_get_select_users AS $FUNCTION$
DECLARE
BEGIN
RETURN QUERY SELECT
t1.uuid, t1.name, t2.name
FROM
users AS t1
INNER JOIN companies AS t2 ON (t1.company_uuid = t2.uuid);
END;
$FUNCTION$ LANGUAGE plpgsql;