(plpgsql) DECLARE foo NUMERIC(5,2): syntax error at "("

Started by Angus Leesabout 24 years ago2 messagesbugs
Jump to latest
#1Angus Lees
gus@switchonline.com.au

PL/pgSQL docs say "PL/pgSQL variables can have any SQL datatype".

but when i try:

CREATE FUNCTION foo() RETURNS NUMERIC(5,2) AS '
DECLARE
bar NUMERIC(5,2);
BEGIN
bar := 123.45;
return bar;
END;
' LANGUAGE 'plpgsql';

then "select foo()" gives:
NOTICE: plpgsql: ERROR during compile of foo near line 2
ERROR: parse error at or near "("

declaring bar as "FLOAT8" (for example) works as expected.

from a quick look at plpgsql/src/gram.y, the decl_dtypename rule
only allows type modifiers (decl_attypmod) on CHAR, VARCHAR or BPCHAR.

scan.l doesn't even recognise NUMERIC or DECIMAL as keywords.

(debian postgresql 7.1.3-6 package on Linux/Intel)

--
- Gus

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Angus Lees (#1)
Re: (plpgsql) DECLARE foo NUMERIC(5,2): syntax error at "("

Angus Lees <gus@switchonline.com.au> writes:

from a quick look at plpgsql/src/gram.y, the decl_dtypename rule
only allows type modifiers (decl_attypmod) on CHAR, VARCHAR or BPCHAR.

This is fixed in 7.2.

regards, tom lane