"too clever" when creating SQL functions - Mailing list pgsql-sql

From SZŰCS Gábor
Subject "too clever" when creating SQL functions
Date
Msg-id 010d01c314c1$3ba30950$0a03a8c0@fejleszt2
Whole thread Raw
Responses Re: "too clever" when creating SQL functions  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
Dear Gurus,

Please show me to the archives, if you feel like. I have an ugly function
that can't be defined as language SQL, because it gets parsed at
define-time, not run-time. Any ideas, other than making it plpgsql?

Even better, is there a more elegant way to turn off/on triggers on a (set
of) table(s)?

The function and what psql says is at the end of this message.

G.
--
while (!asleep()) sheep++;

---------------------------- cut here ------------------------------
bin=# CREATE OR REPLACE FUNCTION triggers_on(name) RETURNS int AS '
bin'#   CREATE TEMP TABLE tr (tmp_relname name, tmp_reltriggers smallint);
bin'#
bin'#   INSERT INTO tr
bin'#     SELECT C.relname, count(T.oid)
bin'#     FROM pg_class C, pg_trigger T
bin'#     WHERE C.oid = T.tgrelid AND C.relname ~* $1
bin'#     GROUP BY 1;
bin'#   UPDATE pg_class SET reltriggers = TMP.tmp_reltriggers
bin'#   FROM tr TMP
bin'#   WHERE pg_class.relname = TMP.tmp_relname;
bin'#
bin'#   DROP TABLE tr;
bin'#   SELECT 1;
bin'# ' LANGUAGE 'SQL';
ERROR:  Relation "tr" does not exist
---------------------------- cut here ------------------------------



pgsql-sql by date:

Previous
From: Josh Berkus
Date:
Subject: Re: index defragmentation
Next
From:
Date:
Subject: Re: [GENERAL] PostgreSQL Qs