0

can anybody tell me, how to write function in plpgsql, which generates html table and is called like this:

SELECT funktionName( 'Select name, salary*1.2 from employees where salary IN ( SELECT MIN(SALARY) from employees where salary>'||salary||') ' ) from employees where ssn=111;

Thanks for help.

1
  • +1 and @whoever-downvoted this is not a bad question so why vote it down? Commented Dec 13, 2010 at 18:37

2 Answers 2

1

You can generate XML using Postgres' XML features and transform that into HTML using XSLT. There is an example for that in the manual

But this is definitely not a recommended approach.

Sign up to request clarification or add additional context in comments.

4 Comments

"But this is definitely not a recommended approach." -- Why not?
@ObiWanKenobi What I would worry about re: generating html in the db is that as presentation needs change, you end up having to rewrite all your stored procedures. It also reduces re-use of code. I am not saying there isn't a time or place for it. For example being able to take arbitrary DB objects and create a semantic XHTML document out of them might be relatively useful. However, I would be relatively careful and use this approach sparingly.
@ChrisTravers: "as presentation needs change, you end up having to rewrite all your stored procedures" -- Actually, no, since the original poster's suggestion was to generate XML, and then apply XSLT to that to create the HTML, which means that as presentation needs change, you don't change your stored procedure at all, just your XSLT...
Depends. Are you doing XSLT in your stored procedure? I mean you could do that using one of the PLs and output xhtml, right?
0

Another interesting approach would be to download and install http://www.commandprompt.com/community/plphp/

You could then use PHP to write templates for the XML that would be executed in the db.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.