0
我試圖創建一個函數,在其中一個表字段中搜索字符串,然後返回一個新的用戶表。基本上,一個表裏面我有Postgresql執行功能
create table fooSearchTable (
id integer, -- PG: serial
name LongName unique not null,
queryDef LongString not null,
primary key (id)
);
其中queryDef
是保存另一個查詢執行字符串。例如,一個行可能是
1 | resultName | select * from users where users.id = '4'
我得到了這個函數格式
create or replace function searchUsers(_searchName text) returns table (userID integer) as $$
begin
end;
$$ language plpgsql stable;
我需要運行一個SQL查詢來查找該行的_searchName
比賽與是
select queryDef from fooSearchTable f
where f.name = _searchName;
這將返回字符串,但我不知道如何在函數中執行此字符串,所以我可以得到一個userIDs表。任何幫助,將不勝感激。
我猜想你讀過的[精說明書(http://www.postgresql.org/docs/current/static/plpgsql-statements.html# PLPGSQL-STATEMENTS-EXECUTING-DYN)說這個話題? –
@ MilenA.Radev有點困惑如何從手冊中顯示的應用它 – SNpn