Neat trick to make sure plpgsql is installed as part of a schema

From: Tyler MacDonald <tyler(at)yi(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Neat trick to make sure plpgsql is installed as part of a schema
Date: 2006-02-06 00:41:14
Message-ID: 20060206004113.GF13399@yi.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hey,

I was puzzling over how to make sure a database has plpgsql
installed in it in pure SQL. I felt this would simplify the schema's
installation process since calling of extra binaries is no longer
neccessary. Here's what I came up with:

CREATE OR REPLACE FUNCTION make_plpgsql () RETURNS bool AS
'
CREATE TRUSTED LANGUAGE "plpgsql" HANDLER "plpgsql_call_handler"; --
SELECT true; --
' LANGUAGE SQL;

SELECT CASE WHEN
(SELECT COUNT(oid) > 0 FROM pg_language WHERE lanname = 'plpgsql')
THEN true ELSE
(SELECT make_plpgsql())
END
;

Cheers,
Tyler

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2006-02-06 02:18:12 Re: logging settings
Previous Message Steve Atkins 2006-02-05 23:31:11 Re: SELECT with REAL...