0

I have created following function in PostgreSQL database

CREATE or REPLACE FUNCTION getSR15ReportData(value text) 
RETURNS  TABLE(
    userid integer,
    username varchar(50)
) AS -- text AS --
$body$
DECLARE
    fullsql TEXT;
    records RECORD;
    exeQuery TEXT;
BEGIN

fullsql:= 'SELECT userid, username from user_index where status='''value'''';

exeQuery := 'SELECT * FROM (' || fullsql || ') AS records';

RETURN QUERY EXECUTE exeQuery;

END
$body$
LANGUAGE plpgsql;

It's giving me output as follow:

getdate
--------------
501,alexanda
502,cathie

But I need output like:

userid  username
------|---------
501,alexanda
502,cathie
1
  • seems he separated the questions but still references the reformatting of the output in his other question. Commented Dec 18, 2013 at 15:55

1 Answer 1

0

I was silly about this question. It was so simple. Thanks a_horse_with_no_name. He has solved this on my another question Get data from PostgreSQL function to java

Just need to call the function:

SELECT * FROM getdata('active')

The full query will look like:

SELECT usr.username 
FROM cust_invoice_index as inv
 JOIN (SELECT * FROM getdata('active')) as usr ON usr.userid=inv.userid_edit
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.