sql - "How do I use a variable in plpgpsql in a where clause?" -


i have function created in plpgsql. function has cursor called cursor_ , while fetch values of cursor, query performed inside loop. query uses condition data cursor. problem variable name_var empty when function perform query, in spite of changes values retrieved cursor. doign wrong?. here code:

create or replace function fn_return_company_centers()  returns  table(company text, centers text) $body$  declare cursor_ cursor select c.name, m.location || '__' || m.storagekey center                    company c inner join monitor m on c.id = m.company_id                    order c.name; v_parent_rec record; name_var text :=''; _centros text := ''; pos int := 0;  begin     create temporary table if not exists tmp_company_center (company text, centers text);     delete tmp_company_center;      v_parent_rec in cursor_  loop         if name_var = ''             name_var := v_parent_rec.name;               select a.centros _centros              scheduler_report             a.empresa = name_var ;              pos := position(v_parent_rec.center in _centros);             raise notice 'es %', pos;      end loop;     return query select * tmp_company_center order company; end; $body$   language plpgsql volatile   cost 100   rows 1000; 

thnks in advance,

daniel.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -