logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Bug in PostGre SQL-script
quandary
#1 Posted : Sunday, February 05, 2012 9:33:02 PM(UTC)
Rank: Advanced Member

Groups: Member
Joined: 6/6/2010(UTC)
Posts: 39
Points: 120
Location: Switzerland

Hi !

When I let the PostGre script running, I got strange error messages on the production server.
Finding the real error wasn't all that easy, but in the end, it all boils down to
Quote:

ERROR: language "plpgsql" does not exist



When you run
Code:

SELECT lanname, lanowner, lanispl, lanpltrusted, lanplcallfoid, lanvalidator, 
       lanacl
FROM pg_language;

on older servers (where the database has not been created using template0/1), such as stable production servers, you will see that no such language is included.

So, add the below part as the very top of the script.
(Taken from http://timmurphy.org/201...nt-exist-in-postgresql/ )

Code:

CREATE OR REPLACE FUNCTION create_language_plpgsql()
RETURNS BOOLEAN AS $$
    CREATE LANGUAGE plpgsql;
    SELECT TRUE;
$$ LANGUAGE SQL;

SELECT CASE WHEN NOT
    (
        SELECT  TRUE AS exists
        FROM    pg_language
        WHERE   lanname = 'plpgsql'
        UNION
        SELECT  FALSE AS exists
        ORDER BY exists DESC
        LIMIT 1
    )
THEN
    create_language_plpgsql()
ELSE
    FALSE
END AS plpgsql_created;

DROP FUNCTION create_language_plpgsql();

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.5.5 | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.019 seconds.