"too clever" when creating SQL functions

From: SZŰCS Gábor <surrano(at)mailbox(dot)hu>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: "too clever" when creating SQL functions
Date: 2003-05-07 17:51:05
Message-ID: 010d01c314c1$3ba30950$0a03a8c0@fejleszt2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 ------------------------------

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message mallah 2003-05-07 18:01:24 Re: [GENERAL] PostgreSQL Qs
Previous Message Richard Huxton 2003-05-07 17:32:22 Re: PostgreSQL Qs