Skip site navigation (1) Skip section navigation (2)

Re: ERROR: $1 is declared CONSTANT in plpgsql

From: "Henshall, Stuart - WCP" <SHenshall(at)westcountrypublications(dot)co(dot)uk>
To: 'Hans Plum' <plum(at)giub(dot)uni-bonn(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: ERROR: $1 is declared CONSTANT in plpgsql
Date: 2002-05-07 16:13:26
Message-ID: E2870D8CE1CCD311BAF50008C71EDE8E01F74884@MAIL_EXCHANGE (view raw or flat)
Thread:
Lists: pgsql-novice
I'd guess this line is the problem:
		InpAscii := $1;
I believe this parses to
		$1:=$1;
and a bit later down:
		InpAscii := Part1 || CharMap.html || Part2 ;
would, I believe, parse to
		$1:=Part1 || CharMap.html || Part2;
I don't know wether it is permitted to assign values to
the arguments passed (although I'd imagine not),
but I don't do it myself.
Cheers,
- Stuart


> -----Original Message-----
> From: Hans Plum [mailto:plum(at)giub(dot)uni-bonn(dot)de]
> 
> Hello folks,
> I wrote my first plpgsql-functions for PostgreSQL 7.1.3. I try to 
> convert Ascii-Strings in HTML-conform Strings  (Converting 
> 'Äquator' -> 
> '&Auml;quator') ... Now I get a error message like this:
> 
> NOTICE:  plpgsql: ERROR during compile of f_ascii2html near line 7
> ERROR:  $1 is declared CONSTANT
> 
> For me $1, or better InpAscii is not CONSTANT ... I cannot find the 
> mistake ... Can anybody help out?
> 
> Hopefully, you can reproduce the error with the code right here.
> 
> Thanks a lot,
> Hans
> 
> PS:
> There is some debug-code that I have not used because the 
> functions does 
> not work ;-)).
> 
> -- BEGIN OF SKRIPT ...
> 
> 
> DROP TABLE t_ascii2html;
> 
> /* table for replacing letters */
> 
> CREATE TABLE t_ascii2html (
> 	ascii VARCHAR(1),
> 	html VARCHAR(20)
> );
> 
> INSERT INTO t_ascii2html VALUES ('ä','&auml;');
> INSERT INTO t_ascii2html VALUES ('ö','&ouml;');
> INSERT INTO t_ascii2html VALUES ('ü','&uuml;');
> INSERT INTO t_ascii2html VALUES ('Ä','&auml;');
> INSERT INTO t_ascii2html VALUES ('Ö','&ouml;');
> INSERT INTO t_ascii2html VALUES ('Ü','&uuml;');
> INSERT INTO t_ascii2html VALUES ('ß','&szlig;');
> INSERT INTO t_ascii2html VALUES ('"','&quot;');
> INSERT INTO t_ascii2html VALUES ('&','&amp;');
> INSERT INTO t_ascii2html VALUES ('<','&lt;');
> INSERT INTO t_ascii2html VALUES ('>','&gt;');
> 
> 
> DROP FUNCTION f_ascii2html(TEXT);
> 
> 
> /* Converting 'special' letters (eg. german umlaute like "ö") into a
> HTML-conform string */
> 
> CREATE FUNCTION f_ascii2html(TEXT)
> 	RETURNS TEXT
> 	AS '
> 		DECLARE
> 		InpAscii ALIAS FOR $1;
> 		CharMap RECORD;
> 		InsertPosition INTEGER;
> 		Part1 TEXT;
> 		Part2 TEXT;
> 		BEGIN
> 		InpAscii := $1;
> 		
> 			-- Select all datasets from the table 
> describing the replacement
> 			FOR CharMap IN SELECT * FROM f_ascii2html LOOP
> 				RAISE NOTICE ''CharMap --- 
> ASCII: %, HTML: %'', t_ascii2html.ascii, 
> t_ascii2html.html;
> 				
> 				WHILE InpAscii ~ CharMap.ascii
> 					RAISE NOTICE 
> ''INPASCII: %'', InpAscii;
> 					SELECT 
> position(InpAscii IN CharMap.ascii)
> 					INTO InsertPosition;
> 					RAISE NOTICE 
> ''INSERTPOSITION: %'', InsertPosition;
> 					SELECT substrg(InpAscii 
> FROM (InsertPosition - 1))
> 					INTO Part1;
> 					RAISE NOTICE ''PART1: 
> %'', Part1;
> 					SELECT substrg(InpAscii 
> FROM (InsertPosition + 1))
> 					INTO Part2;
> 					RAISE NOTICE ''PART2: 
> %'', Part2;
> 					InpAscii := Part1 || 
> CharMap.html || Part2 ;
> 					RAISE NOTICE 
> ''INPASCII: %'', InpAscii;
> 				END LOOP;
> 			END LOOP;
> 		RAISE NOTICE ''InpAscii: %'', InpAscii;
> 		RETURN InpAscii	
> 		END;
> 	   '
> 	
> 	 LANGUAGE 'plpgsql';
> 	
> /* Sample: Converting 'Äquator' -> '&Auml;quator' */
> 
> select f_ascii2html('Äquator');
> 
> /* I get the following error message:
> NOTICE:  plpgsql: ERROR during compile of f_ascii2html near line 7
> ERROR:  $1 is declared CONSTANT
> */

pgsql-novice by date

Next:From: Josh BerkusDate: 2002-05-07 17:35:11
Subject: Re: Stored Procedures
Previous:From: Oliver ElphickDate: 2002-05-07 14:50:42
Subject: Re: ERROR: $1 is declared CONSTANT in plpgsql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group