SET client_encoding = 'UNICODE';
SET check_functions_bodies = false;

SET search_path = public, pg_catalog;

CREATE TYPE "test_type" AS (
	"id" integer,
	"name" character varying(64),
	"description" text
);

CREATE FUNCTION "test"(character varying) RETURNS "test_type"
    AS '
  select "id", "name", "description"
    from "test"
    where "name" = $1;
'
    LANGUAGE sql SECURITY DEFINER;

CREATE FUNCTION "test2"(character varying) RETURNS SETOF "test_type"
    AS '
  select "id", "name", "description"
    from "test"
    where "name" = $1;
'
    LANGUAGE sql SECURITY DEFINER;


SET default_with_oids = true;

CREATE TABLE "test" (
    "id" serial NOT NULL,
    "name" character varying(64) NOT NULL,
    "description" text,
    "update_time" timestamp without time zone DEFAULT now() NOT NULL
);

SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('test', 'id'), 1, false);

INSERT INTO "test" ("id", "name", "description", "update_time") VALUES (1, 'first', 'first row', '2004-09-21 15:32:41.171');
INSERT INTO "test" ("id", "name", "description", "update_time") VALUES (2, 'second', 'second row', '2004-09-21 15:32:54.64');
INSERT INTO "test" ("id", "name", "description", "update_time") VALUES (3, 'third', 'third row', '2004-09-21 15:33:08.406');

ALTER TABLE ONLY "test"
    ADD CONSTRAINT "pk_test_id" PRIMARY KEY ("id");

ALTER TABLE ONLY "test"
    ADD CONSTRAINT "unq_test_name" UNIQUE ("name");

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


