Re: [GENERAL] return text from explain

2012-09-07 Thread Willy-Bas Loos
cool, it does work with RETURN QUERY. Thanx! WBL On Fri, Sep 7, 2012 at 11:00 AM, Виктор Егоров wrote: > Hope this helps: > > CREATE OR REPLACE FUNCTION explain(in_sql text) RETURNS TABLE(explain_line > text) AS $explain$ > BEGIN > RETURN QUERY EXECUTE 'EXPLAIN '||in_sql; > END; > $explain

Re: [GENERAL] return text from explain

2012-09-07 Thread Виктор Егоров
Hope this helps: CREATE OR REPLACE FUNCTION explain(in_sql text) RETURNS TABLE(explain_line text) AS $explain$ BEGIN RETURN QUERY EXECUTE 'EXPLAIN '||in_sql; END; $explain$ LANGUAGE plpgsql; SELECT * FROM explain('SELECT * FROM pg_locks'); -- Victor Y. Yegorov

Re: [GENERAL] return text from explain

2012-09-07 Thread Willy-Bas Loos
On Thu, Sep 6, 2012 at 10:15 PM, Tom Lane wrote: > Bruce Momjian writes: > > On Thu, Sep 6, 2012 at 07:18:50PM +0200, Willy-Bas Loos wrote: > >> Is it possible to use the output of explain as text values? > > > I think you have to do EXPLAIN in a function and call the function. > > Yeah, IIRC y

Re: [GENERAL] return text from explain

2012-09-06 Thread Tom Lane
Bruce Momjian writes: > On Thu, Sep 6, 2012 at 07:18:50PM +0200, Willy-Bas Loos wrote: >> Is it possible to use the output of explain as text values? > I think you have to do EXPLAIN in a function and call the function. Yeah, IIRC you can use EXPLAIN as the source statement in a plpgsql FOR loo

Re: [GENERAL] return text from explain

2012-09-06 Thread Willy-Bas Loos
Buce, thx for answering. I cant't find the example you mean. Tried a function, but won't work.. create or replace function test() returns setof record as $$ declare t_rec record; begin for t_rec in ( explain select * from (values ('a'),('b'), ('c')) foo(x) where x > 'a' ) loop return next t_r

Re: [GENERAL] return text from explain

2012-09-06 Thread Bruce Momjian
On Thu, Sep 6, 2012 at 07:18:50PM +0200, Willy-Bas Loos wrote: > Hi, > > Is it possible to use the output of explain as text values? > This won't work: > > explain select * > from (values (1),(2),(3)) foo(x) > where x > 2 > > What i really want is to explain analyze a dynamic query that i build

Re: [GENERAL] return text from explain

2012-09-06 Thread Willy-Bas Loos
correction. What won't work is: select y||'--some text' from ( explain select * from (values (1),(2), (3)) foo(x) where x > 2 ) bar(y) Cheers, WBL On Thu, Sep 6, 2012 at 7:18 PM, Willy-Bas Loos wrote: > Hi, > > Is it possible to use the output of explain as text values? > This won't work: > >