From: | Hans Plum <plum(at)giub(dot)uni-bonn(dot)de> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | ERROR: $1 is declared CONSTANT in plpgsql |
Date: | 2002-05-07 11:18:40 |
Message-ID: | 3CD7B810.7000009@giub.uni-bonn.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
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' ->
'Ä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 ('ä','ä');
INSERT INTO t_ascii2html VALUES ('ö','ö');
INSERT INTO t_ascii2html VALUES ('ü','ü');
INSERT INTO t_ascii2html VALUES ('Ä','ä');
INSERT INTO t_ascii2html VALUES ('Ö','ö');
INSERT INTO t_ascii2html VALUES ('Ü','ü');
INSERT INTO t_ascii2html VALUES ('ß','ß');
INSERT INTO t_ascii2html VALUES ('"','"');
INSERT INTO t_ascii2html VALUES ('&','&');
INSERT INTO t_ascii2html VALUES ('<','<');
INSERT INTO t_ascii2html VALUES ('>','>');
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' -> 'Ä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
*/
From | Date | Subject | |
---|---|---|---|
Next Message | Joseph.ROTHWELL | 2002-05-07 12:54:59 | Problems with psql : ERROR : pg_user: permission denied,and I can 't type \ in psql |
Previous Message | Richard A Lough | 2002-05-06 20:39:42 | Re: Date Formatting |