Обсуждение: create function bug?
Using a snapshot from two days ago on a i586-pc-linux-gnu using linux-elf template: test=> create table test (t1 integer); CREATE test=> create function myfunc (integer) returns integer test-> as 'select $1' language 'sql'; ERROR: ProcedureCreate: arg type 'integer' is not defined test=> create function myfunc(int4) returns int4 test-> as 'select $1' language 'sql'; CREATE I can use the integer type in tables, but not in functions. Is this a bug? Ewan Mellor.
I noticed that too, but since I don't use 'integer' in tables, I figured postgres didn't have the "integer" type (which probably should have struck me as odd). It might be one of these silly grammer rewrites, in which case (if there isn't central type/function parsing code it seems like more trouble than it's worth, I mean why not just have the extra type/functions in the catalogs? or have aliases somehow?) I'm sure you can work around it ;) On Thu, 5 February 1998, at 17:00:15, Ewan Mellor wrote: > Using a snapshot from two days ago on a i586-pc-linux-gnu using > linux-elf template: > > test=> create table test (t1 integer); > CREATE > test=> create function myfunc (integer) returns integer > test-> as 'select $1' language 'sql'; > ERROR: ProcedureCreate: arg type 'integer' is not defined > test=> create function myfunc(int4) returns int4 > test-> as 'select $1' language 'sql'; > CREATE > > I can use the integer type in tables, but not in functions. Is this a > bug? > > Ewan Mellor.
After going over the grammer and function code, there's a little bit of weirdness I see. I don't know the correct terminology, but the grammer for typname is a little odd. in the first case (i.e. txname) it does some type translating itself (flort => float8, decimal => integer, numeric => integer) before calling xlateSqlType, which does the same thing, but with the following types: (int/integer => int4, smalling => int2, real => float8, interval => timespan) in the second case (SETOF txname), none of this pre-xlateSqlType translating is done. is it safe to assume someone put this code in the wrong place (not in xlateSqlType so it would apply to all types)? is the grammar the best place for this "type aliasing"? would it be safe to modify the create function grammer to call xlateSqlType (so long as opaque does not get aliased to anything? ;) --brett > On Thu, 5 February 1998, at 17:00:15, Ewan Mellor wrote: > > > Using a snapshot from two days ago on a i586-pc-linux-gnu using > > linux-elf template: > > > > test=> create table test (t1 integer); > > CREATE > > test=> create function myfunc (integer) returns integer > > test-> as 'select $1' language 'sql'; > > ERROR: ProcedureCreate: arg type 'integer' is not defined > > test=> create function myfunc(int4) returns int4 > > test-> as 'select $1' language 'sql'; > > CREATE > > > > I can use the integer type in tables, but not in functions. Is this a > > bug? > > > > Ewan Mellor.
On Thu, 5 Feb 1998, Ewan Mellor wrote: > test=> create function myfunc (integer) returns integer > test-> as 'select $1' language 'sql'; On most PLs that I used, you need to specify a variable name for the param, after all, how are you going to refer to it? Try: create function myfunc (myint integer) returns integer as 'select $1' language 'sql'; Tom
> is it safe to assume someone put this code in the wrong place (not in > xlateSqlType so it would apply to all types)? is the grammar the best > place for this "type aliasing"? would it be safe to modify the create > function grammer to call xlateSqlType (so long as opaque does not get > aliased to anything? ;) > > > Using a snapshot from two days ago on a i586-pc-linux-gnu using > > > linux-elf template: <snip> > > > I can use the integer type in tables, but not in functions. Is this a > > > bug? This behavior must have been in the code for a long time. Anyway, I'll fix it for v6.3 (I have some other similar fixes for function names ready to commit and I'll do both at the same time). "integer" is translated into "int4" in the parser, to avoid having to replicate the declarations for the support code. Specify the actual type name and your declaration will work now. - Tom