I have below two tables and two pl/pgsql
functions.
CREATE TABLE tt1(id int, name text);
CREATE TABLE tt2(id int, name text);
INSERT INTO tt1 VALUES (1,'name1');
INSERT INTO tt1 VALUES (2,'name2');
INSERT INTO tt1 VALUES (3,'name3');
INSERT INTO tt2 VALUES (4,'name4');
INSERT INTO tt2 VALUES (5,'name5');
INSERT INTO tt2 VALUES (6,'name6');
CREATE OR REPLACE FUNCTION query_string() RETURNS TEXT AS
$BODY$
DECLARE
query1 TEXT:='';
BEGIN
query1 := 'SELECT * FROM tt1 UNION ALL SELECT * FROM tt2';
RETURN query1;
END;
$BODY$
LANGUAGE PLPGSQL;
CREATE OR REPLACE FUNCTION use_generated_string() RETURNS VOID AS
$BODY$
DECLARE
BEGIN
-- Need to modify here to get the result same as below query by
-- calling above function.
-- "SELECT * FROM tt1 UNION ALL SELECT * FROM tt2"
END;
$BODY$
LANGUAGE PLPGSQL;
query_string
function returns the query string.
How can i modify the "use_generated_string" function so that I can get the result of the below query by calling the use_generated_string
function.
SELECT * FROM tt1 UNION ALL SELECT * FROM tt2;
Can anyone help ?