Creating Trigger function is psql "syntax error at or near "CREATE""
<p>Here is my postgreSQL code</p>

<pre><code>CREATE FUNCTION connectedExhibitionFunction()
RETURNS trigger AS
$$
BEGIN
        IF (SELECT COUNT("exName") FROM Exhibitions WHERE NEW."exName" = "exName") &gt; 0 THEN
                IF (SELECT Count(doorLoc1) FROM Doors, ExhibitionLocations WHERE (dorLoc1=NEW.elLocation AND dorLoc2=elLocations) OR (dorLoc2=NEW.elLocation AND dorLoc1=elLocations) &gt; 0 THEN
                        RAISE EXCEPTION 'You can't have the exhibition there, the same exhibition is in an unconnected room';
                END IF;
        END IF;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER connectedExhibitionTrigger
        BEFORE INSERT
        ON ExhibitionsLocations
        EXECUTE PROCEDURE connectedExhibitionFunction();
</code></pre>

<p>And this is the error I'm getting</p>

<pre><code>psql:file.txt:62: ERROR:  syntax error at or near "CREATE"
LINE 8: CREATE FUNCTION connectedExhibitionFunction()
        ^
psql:file.txt:67: ERROR:  current transaction is aborted, commands ignored until end of transaction block
</code></pre>

<p>I can't seem to figure out the error, can anybody spot anything here?</p>