Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id C13E09FA26D for ; Wed, 17 Jan 2007 18:33:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 95906-09 for ; Wed, 17 Jan 2007 18:33:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from cicero0.cybercity.dk (cicero0.cybercity.dk [212.242.40.52]) by postgresql.org (Postfix) with ESMTP id 65F269F93E5 for ; Wed, 17 Jan 2007 18:33:22 -0400 (AST) Received: from agile.dk (0x3e42da3b.adsl.cybercity.dk [62.66.218.59]) by cicero0.cybercity.dk (Postfix) with ESMTP id B6EF567858D for ; Wed, 17 Jan 2007 23:33:20 +0100 (CET) Received: from mail.agile.dk (localhost [127.0.0.1]) by agile.dk (Postfix) with ESMTP id 6D04EB0B81 for ; Wed, 17 Jan 2007 23:33:19 +0100 (CET) Received: from 62.66.218.59 (SquirrelMail authenticated user jma@agile.dk) by mail.agile.dk with HTTP; Wed, 17 Jan 2007 23:33:19 +0100 (CET) Message-ID: <1364.62.66.218.59.1169073199.squirrel@mail.agile.dk> Date: Wed, 17 Jan 2007 23:33:19 +0100 (CET) Subject: Some help with functions-syntax From: "Jan Meyland Andersen" To: pgsql-sql@postgresql.org User-Agent: SquirrelMail/1.4.4 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.115 tagged_above=0 required=5 tests=AWL, BAYES_50, FORGED_RCVD_HELO, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200701/72 X-Sequence-Number: 27224 I have some problem with writing a function. I have made this function which I can't get it to work. This is probaly a triviel question but i'm new to plsql, so this is a showstopper for me. DECLARE _relkind char; _RES "EMS"."KeySet"; _WHERECLAUSE text; BEGIN SELECT pgc.relkind INTO _relkind FROM pg_class pgc JOIN pg_namespace pgn ON pgc.relnamespace=pgn.oid WHERE pgn.nspname=$1 AND pgc.relname=$2; IF _relkind = 'r' THEN _WHERECLAUSE := '(fknam.nspname = ''$1'' AND fkc.relname = ''$2'')'; END IF; IF _relkind = 'v' THEN _WHERECLAUSE := ''; END IF; FOR _RES IN SELECT fknam.nspname AS "FKTABLE_SCHEM", fkc.relname AS "FKTABLE_NAME", fka.attname AS "FKCOLUMN_NAME", pknam.nspname AS "PKTABLE_SCHEM", pkc.relname AS "PKTABLE_NAME", pka.attname AS "PKCOLUMN_NAME", fkcon.conname AS "FK_NAME", pkcon.conname AS "PK_NAME", CASE WHEN pkcon.contype = 'p' THEN 'PRIMARY' WHEN pkcon.contype = 'u' THEN 'UNIQUE' END AS "UNIQUE_OR_PRIMARY" FROM pg_constraint AS fkcon JOIN pg_namespace AS fknam ON fkcon.connamespace=fknam.oid JOIN pg_class AS fkc ON fkc.oid=fkcon.conrelid JOIN pg_attribute fka ON fka.attrelid=fkc.oid AND fka.attnum = ANY(fkcon.conkey) JOIN pg_constraint AS pkcon ON fkcon.confrelid=pkcon.conrelid AND fkcon.confkey=pkcon.conkey JOIN pg_namespace pknam ON pkcon.connamespace=pknam.oid JOIN pg_class pkc ON pkc.oid=fkcon.confrelid JOIN pg_attribute pka ON pka.attrelid=pkc.oid AND pka.attnum = some(pkcon.conkey) WHERE ( (pkcon.conkey[1] = pka.attnum AND fkcon.conkey[1] = fka.attnum) OR (pkcon.conkey[2] = pka.attnum AND fkcon.conkey[2] = fka.attnum) OR (pkcon.conkey[3] = pka.attnum AND fkcon.conkey[3] = fka.attnum) OR (pkcon.conkey[4] = pka.attnum AND fkcon.conkey[4] = fka.attnum) OR (pkcon.conkey[5] = pka.attnum AND fkcon.conkey[5] = fka.attnum) ) AND || _WHERECLAUSE LOOP RETURN NEXT _RES; END LOOP; RETURN; END; I get the following error: ERROR: operator does not exist: || text SQL state: 42883 Hint: No operator matches the given name and argument type(s). You may need to add explicit type casts. How do I solve this? I also have a question about how to write CASE-statement? I am only able to use if. Regards Jan