Discussion:
[ADMIN] ERROR: there is no parameter $1
(too old to reply)
Madhu.Lanka
2012-07-20 02:33:36 UTC
Permalink
Hi Friends



I am creating the function like



CREATE OR REPLACE FUNCTION getrowstest3(pname character varying,ppassword
character varying)

RETURNS SETOF getrows AS

$BODY$

declare

r getrows;

begin

for r in EXECUTE

'select
u.role_id,u.user_id,p.name,p.creation_date,p.telephone_number,p.email,p.rema
rks,p.city,p.state,p.country,p.postal_address,p.company_name,p.department_na
me,p.contact_person,

p.role_group,p.role_description,p.first_name,p.last_name,p.pincode,p.status,
p.department_id,p.designation_id,r.role_name,r.right_edit,r.right_filter,r.r
ight_search,r.right_browse,

r.right_print,r.right_download,r.right_admin_user,r.right_image_creator,r.ri
ght_vector_download,r.right_wps,r.right_queries_filter,r.right_google_map,r.
right_user_management,

r.right_route_analysis,r.right_legend,r.right_treeview,r.insert,r.update,r.d
elete,r.query,r.lock from ksdi.user_roles u,ksdi.principals p,ksdi.roles r
where p.PRINCIPAL_ID = u.USER_ID and

r.role_id = u.role_id and p.name =$1 and p.password = $2;'

loop

return next r;

end loop;

return;

end

$BODY$

LANGUAGE plpgsql VOLATILE

COST 100

ROWS 1000;



Where getrows is the type created by me;

It is created successfully.

I am trying to call the function I pgadmin with the following command

select * from getrowstest2('general_user','***@123');



I am getting the following error



ERROR: there is no parameter $1

LINE 5: r.role_id = u.role_id and p.name= $1 and p.password = $2

^

QUERY: select
u.role_id,u.user_id,p.name,p.creation_date,p.telephone_number,p.email,p.rema
rks,p.city,p.state,p.country,p.postal_address,p.company_name,p.department_na
me,p.contact_person,

p.role_group,p.role_description,p.first_name,p.last_name,p.pincode,p.status,
p.department_id,p.designation_id,r.role_name,r.right_edit,r.right_filter,r.r
ight_search,r.right_browse,

r.right_print,r.right_download,r.right_admin_user,r.right_image_creator,r.ri
ght_vector_download,r.right_wps,r.right_queries_filter,r.right_google_map,r.
right_user_management,

r.right_route_analysis,r.right_legend,r.right_treeview,r.insert,r.update,r.d
elete,r.query,r.lock from ksdi.user_roles u,ksdi.principals p,ksdi.roles r
where p.PRINCIPAL_ID = u.USER_ID and

r.role_id = u.role_id and p.name= $1 and p.password = $2

CONTEXT: PL/pgSQL function "getrowstest2" line 8 at FOR over EXECUTE
statement



********** Error **********



ERROR: there is no parameter $1

SQL state: 42P02

Context: PL/pgSQL function "getrowstest2" line 8 at FOR over EXECUTE
statement



Can anyone please help me to resolve the issue.



Thanks in Advance



Regards

Madhu.Lanka
Sergey Konoplev
2012-07-20 04:25:58 UTC
Permalink
Post by Madhu.Lanka
I am getting the following error
ERROR: there is no parameter $1
LINE 5: r.role_id = u.role_id and p.name= $1 and p.password = $2
Because they are not expanding inside strings. Use EXECUTE ... USING ...

EXECUTE '... and p.name =$1 and p.password = $2;' USING pname, ppassword
--
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: ***@gmail.com Skype: gray-hemp Phone: +79160686204
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Martin French
2012-07-20 07:30:47 UTC
Permalink
Martin French
2012-07-20 06:34:15 UTC
Permalink
<html><body><p><font size="2" face="sans-serif">Hi </font><br><br><tt><font size="2">pgsql-admin-***@postgresql.org wrote on 20/07/2012 03:33:36:<br><br>&gt; From: &quot;Madhu.Lanka&quot; &lt;***@avineonindia.com&gt;</font></tt><br><tt><font size="2">&gt; To: &lt;pgsql-***@postgresql.org&gt;, </font></tt><br><tt><font size="2">&gt; Date: 20/07/2012 06:37</font></tt><br><tt><font size="2">&gt; Subject: [ADMIN] ERROR: &nbsp;there is no parameter $1</font></tt><br><tt><font size="2">&gt; Sent by: pgsql-admin-***@postgresql.org</font></tt><br><tt><font size="2">&gt; <br>&gt; Hi Friends</font></tt><br><tt><font size="2">&gt; &nbsp;</font></tt><br><tt><font size="2">&gt; I am creating the function like </font></tt><br><tt><font size="2">&gt; &nbsp;</font></tt><br><tt><font size="2">&gt; CREATE OR REPLACE FUNCTION getrowstest3(pname character <br>&gt; varying,ppassword character varying)</font></tt><br><tt><font size="2">&gt; &nbsp; RETURNS SETOF getrows AS</font></tt><br><tt><font size="2">&gt; $BODY$</font></tt><br><tt><font size="2">&gt; declare</font></tt><br><tt><font size="2">&gt; r getrows;</font></tt><br><tt><font size="2">&gt; begin</font></tt><br><tt><font size="2">&gt; for r in EXECUTE </font></tt><br><tt><font size="2">&gt; 'select <br>&gt; u.role_id,u.user_id,p.name,p.creation_date,p.telephone_number,p.email,p.remarks,p.city,p.state,p.country,p.postal_address,p.company_name,p.department_name,p.contact_person,</font></tt><br><tt><font size="2">&gt; p.role_group,p.role_description,p.first_name,p.last_name,p.pincode,p.status,p.department_id,p.designation_id,r.role_name,r.right_edit,r.right_filter,r.right_search,r.right_browse,</font></tt><br><tt><font size="2">&gt; r.right_print,r.right_download,r.right_admin_user,r.right_image_creator,r.right_vector_download,r.right_wps,r.right_queries_filter,r.right_google_map,r.right_user_management,</font></tt><br><tt><font size="2">&gt; r.right_route_analysis,r.right_legend,r.right_treeview,r.insert,r.update,r.delete,r.query,r.lock<br>&gt; from ksdi.user_roles u,ksdi.principals p,ksdi.roles r where <br>&gt; p.PRINCIPAL_ID = u.USER_ID and </font></tt><br><tt><font size="2">&gt; r.role_id = u.role_id and p.name =$1 &nbsp;and p.password = $2;'</font></tt><br><tt><font size="2">&gt; loop</font></tt><br><tt><font size="2">&gt; return next r;</font></tt><br><tt><font size="2">&gt; end loop;</font></tt><br><tt><font size="2">&gt; return;</font></tt><br><tt><font size="2">&gt; end</font></tt><br><tt><font size="2">&gt; $BODY$</font></tt><br><tt><font size="2">&gt; &nbsp; LANGUAGE plpgsql VOLATILE</font></tt><br><tt><font size="2">&gt; &nbsp; COST 100</font></tt><br><tt><font size="2">&gt; &nbsp; ROWS 1000;</font></tt><br><tt><font size="2">&gt; &nbsp;</font></tt><br><tt><font size="2">&gt; Where getrows is the type created by me;</font></tt><br><tt><font size="2">&gt; It is created successfully.</font></tt><br><tt><font size="2">&gt; I am trying to call the function I pgadmin with the following command </font></tt><br><tt><font size="2">&gt; select * from getrowstest2('general_user','***@123');</font></tt><br><tt><font size="2">&gt; &nbsp;</font></tt><br><tt><font size="2">&gt; I am getting the following error </font></tt><br><tt><font size="2">&gt; &nbsp;</font></tt><br><tt><font size="2">&gt; ERROR: &nbsp;there is no parameter $1</font></tt><br><tt><font size="2">&gt; LINE 5: r.role_id = u.role_id and p.name= $1 and p.password = $2</font></tt><br><tt><font size="2">&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</font></tt><br><tt><font size="2">&gt; QUERY: &nbsp;select <br>&gt; u.role_id,u.user_id,p.name,p.creation_date,p.telephone_number,p.email,p.remarks,p.city,p.state,p.country,p.postal_address,p.company_name,p.department_name,p.contact_person,</font></tt><br><tt><font size="2">&gt; p.role_group,p.role_description,p.first_name,p.last_name,p.pincode,p.status,p.department_id,p.designation_id,r.role_name,r.right_edit,r.right_filter,r.right_search,r.right_browse,</font></tt><br><tt><font size="2">&gt; r.right_print,r.right_download,r.right_admin_user,r.right_image_creator,r.right_vector_download,r.right_wps,r.right_queries_filter,r.right_google_map,r.right_user_management,</font></tt><br><tt><font size="2">&gt; r.right_route_analysis,r.right_legend,r.right_treeview,r.insert,r.update,r.delete,r.query,r.lock<br>&gt; from ksdi.user_roles u,ksdi.principals p,ksdi.roles r where <br>&gt; p.PRINCIPAL_ID = u.USER_ID and </font></tt><br><tt><font size="2">&gt; r.role_id = u.role_id and p.name= $1 and p.password = $2</font></tt><br><tt><font size="2">&gt; CONTEXT: &nbsp;PL/pgSQL function &quot;getrowstest2&quot; line 8 at FOR over <br>&gt; EXECUTE statement</font></tt><br><br><tt><font size="2">You have named the parametes in the arguments list:</font></tt><br><br><tt><font size="2"> getrowstest3(pname character varying,ppassword character varying)</font></tt><br><br><tt><font size="2">try the sql with:</font></tt><br><tt><font size="2"> p.name =pname &nbsp;and p.password = ppassword;</font></tt><br><br><tt><font size="2">Cheers</font></tt><br><br><tt><font size="2">Martin</font></tt><font face="sans-serif">=============================================

Romax Technology Limited
Rutherford House
Nottingham Science & Technology Park
Nottingham,
NG7 2PZ
England

Telephone numbers:
+44 (0)115 951 88 00 (main)

For other office locations see:
http://www.romaxtech.com/Contact
=================================
===============
E-mail: ***@romaxtech.com
Website: www.romaxtech.com
=================================

================
Confidentiality Statement
This transmission is for the addressee only and contains information that is confidential and privileged.
Unless you are the named addressee, or authorised to receive it on behalf of the addressee
you may not copy or use it, or disclose it to anyone else.
If you have received this transmission in error please delete from your system and contact the sender. Thank you for your cooperation.
=================================================</font>
</body></html>
Bill MacArthur
2012-07-20 12:50:43 UTC
Permalink
Post by Madhu.Lanka
Hi Friends
I am creating the function like
CREATE OR REPLACE FUNCTION getrowstest3(pname character varying,ppassword character varying)
RETURNS SETOF getrows AS
$BODY$
declare
r getrows;
begin
for r in EXECUTE
'select u.role_id,u.user_id,p.name,p.creation_date,p.telephone_number,p.email,p.remarks,p.city,p.state,p.country,p.postal_address,p.company_name,p.department_name,p.contact_person,
p.role_group,p.role_description,p.first_name,p.last_name,p.pincode,p.status,p.department_id,p.designation_id,r.role_name,r.right_edit,r.right_filter,r.right_search,r.right_browse,
r.right_print,r.right_download,r.right_admin_user,r.right_image_creator,r.right_vector_download,r.right_wps,r.right_queries_filter,r.right_google_map,r.right_user_management,
r.right_route_analysis,r.right_legend,r.right_treeview,r.insert,r.update,r.delete,r.query,r.lock from ksdi.user_roles u,ksdi.principals p,ksdi.roles r where p.PRINCIPAL_ID = u.USER_ID and
r.role_id = u.role_id and p.name =$1 and p.password = $2;'
loop
return next r;
end loop;
return;
end
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;
Where getrows is the type created by me;
It is created successfully.
I am trying to call the function I pgadmin with the following command
**
I am getting the following error
ERROR: there is no parameter $1
LINE 5: r.role_id = u.role_id and p.name= $1 and p.password = $2
^
QUERY: select u.role_id,u.user_id,p.name,p.creation_date,p.telephone_number,p.email,p.remarks,p.city,p.state,p.country,p.postal_address,p.company_name,p.department_name,p.contact_person,
p.role_group,p.role_description,p.first_name,p.last_name,p.pincode,p.status,p.department_id,p.designation_id,r.role_name,r.right_edit,r.right_filter,r.right_search,r.right_browse,
r.right_print,r.right_download,r.right_admin_user,r.right_image_creator,r.right_vector_download,r.right_wps,r.right_queries_filter,r.right_google_map,r.right_user_management,
r.right_route_analysis,r.right_legend,r.right_treeview,r.insert,r.update,r.delete,r.query,r.lock from ksdi.user_roles u,ksdi.principals p,ksdi.roles r where p.PRINCIPAL_ID = u.USER_ID and
r.role_id = u.role_id and p.name= $1 and p.password = $2
CONTEXT: PL/pgSQL function "getrowstest2" line 8 at FOR over EXECUTE statement
********** Error **********
ERROR: there is no parameter $1
SQL state: 42P02
Context: PL/pgSQL function "getrowstest2" line 8 at FOR over EXECUTE statement
Can anyone please help me to resolve the issue.
Thanks in Advance
Regards
Madhu.Lanka
You could shorten this right up and avoid the overhead of plpgsql by making it a pure SQL function without named parameters: (change VOLATILE to STABLE unless you are actually changing something by selecting on those tables)

CREATE OR REPLACE FUNCTION getrowstest3(character varying, character varying)

RETURNS SETOF getrows AS

$BODY$
select u.role_id,u.user_id,p.name,p.creation_date,p.telephone_number,p.email,p.remarks,p.city,p.state,p.country,p.postal_address,p.company_name,p.department_name,p.contact_person,

p.role_group,p.role_description,p.first_name,p.last_name,p.pincode,p.status,p.department_id,p.designation_id,r.role_name,r.right_edit,r.right_filter,r.right_search,r.right_browse,

r.right_print,r.right_download,r.right_admin_user,r.right_image_creator,r.right_vector_download,r.right_wps,r.right_queries_filter,r.right_google_map,r.right_user_management,

r.right_route_analysis,r.right_legend,r.right_treeview,r.insert,r.update,r.delete,r.query,r.lock from ksdi.user_roles u,ksdi.principals p,ksdi.roles r where p.PRINCIPAL_ID = u.USER_ID and

r.role_id = u.role_id and p.name =$1 and p.password = $2
$BODY$

LANGUAGE sql VOLATILE

COST 100

ROWS 1000;
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Loading...