Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execute immediate

Status
Not open for further replies.

ZdenekMach

Programmer
Joined
Dec 19, 2006
Messages
7
Location
CZ
Sorry, but I am novice in postgreSQL so :-)
I have created this function, but it desnt work.
It still tells me:

"ERROR: syntax error at or near "and"na znaku 630"

-- Function: eds_getaccountsdataset(mustbechecked bool, applicatestatus bool, applicatedifferentmaker bool, currentloggedusername "varchar", usernamemaker "varchar", status "varchar")

-- DROP FUNCTION eds_getaccountsdataset(mustbechecked bool, applicatestatus bool, applicatedifferentmaker bool, currentloggedusername "varchar", usernamemaker "varchar", status "varchar");

CREATE OR REPLACE FUNCTION eds_getaccountsdataset(mustbechecked bool, applicatestatus bool, applicatedifferentmaker bool, currentloggedusername "varchar", usernamemaker "varchar", status "varchar")
RETURNS eds_accountsdataset AS

$BODY$
declare
pom integer;
sWhere varchar;
command varchar;
accountdataset eds_accountsdataset;
begin

command :=
'select a."UserName" as UserName, a."FirstName" as FirstName,
a."LastName" as SurName, b."Status" as Status, a."UserNameMaker" as UserName_Maker,
b."UserNameMakerChecker" as UserName_MakerChecker
from "Users" a
inner join
(select c."UserName", c.lastchanged, d."UserNameMakerChecker",
d."Status" from (select "UserName", max("LastChanged") as lastchanged
from "UserStatus"
group by "UserName") c
inner join "UserStatus" d
on c.lastchanged = d."LastChanged" and c."UserName" = d."UserName") b
on a."UserName" = b."UserName" ';
command := command || eds_getaccountsdataset_where(mustbechecked, applicatestatus, applicatedifferentmaker, currentloggedusername, usernamemaker, status);


EXECUTE IMMEDIATE command into accountdataset ;

return accountdataset;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION eds_getaccountsdataset(mustbechecked bool, applicatestatus bool, applicatedifferentmaker bool, currentloggedusername "varchar", usernamemaker "varchar", status "varchar") OWNER TO postgres;
 
Else could I execute immediate in function returns set of something? if I create function returns setof, and than I call the function, it tells me that end of function was reached but no return found.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top