Hello all,
Hereby an alpha version regarding the:
TODO Item: SQL-language reference parameters by name.
I am sending this patch to check if I am on the right track.
So please take a look at this if possible.
What does this patch do?
As discussed in thread: http://archives.postgresql.org/pgsql-hackers/2007-10/msg01490.php,
this patch adds an additional parameter (char **argnames) to pg_parse_and_rewrite and
pg_analyze_and_rewrite and ParseState.
When transformColumnRef is about to report an error for a non existing column,a final match is
performed to see if the non existing column is a parameter name. (argnames)
If true, then a new node is created by transformParamRef
NOTE:
- This patch is created using MSVC++ !
- Nothing is done yet for polymorphic arguments.
My test where:
create table tbl1(id serial,field1 integer,field2 varchar);
insert into tbl1 (field1,field2) values(11,'zzzz');
insert into tbl1 (field1,field2) values(22,'yyyy');
create or replace function func1(par1 integer,par2 integer,par3 varchar) returns setof record as
$$
select
par1::text,
par2,
par1+par2,
par2+par1,
par1+field1,
(field1+par2)::varchar,
par3,
field2 || ' ' || par3
from
tbl1;
$$ language sql;
select func1(2,4,'aaaa');
select * from func1(5,16,'bbbb') as (a text ,b int ,c int, e int, f int,g varchar,h varchar,i text);
results:
"(2,4,6,6,13,15,aaaa,"zzzz aaaa")"
"(2,4,6,6,24,26,aaaa,"yyyy aaaa")"
And
"5";16;21;21;16;"27";"bbbb";"zzzz bbbb"
"5";16;21;21;27;"38";"bbbb";"yyyy bbbb"
Regards,
Gevik