0

Hi I am creating psql reports and at the minute I have two separate reports which do the same thing other than 1 has an extra column.

The scripts install a view in to the database which is used by some php front end to show the report nicely.

I would like to combine the two and wondered if it is possible to do the following inside the view, so it gets executed every time the report is clicked:

IF(access.accessname = 'UNBLINDED')
    SELECT s.site, s.type, s.name etc
ELSE IF(access.accessname = 'BLINDED')
    SELECT s.site, s.name etc

Or if not can anyone else think of a better way to do what I am currently doing with two different scripts?

Thanks for your help

1 Answer 1

2

One common way of handling parameterized data sets is to create user defined functions. This moves the data logic to the data layer and allows the application to simply pass in a parameter (ie: SELECT * FROM new_user_function(access.accessname))

Google can help you find detailed examples and tutorials, and this may help get you started: http://wischner.blogspot.com/2009/03/creating-stored-procedure-function.html

Good luck! ~Rose

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

7 Comments

Thanks, I understand that I'm supposed to do a function. I'm just finding it hard understanding these tutorials. All I want to do is perform some simple selects but one select should contain an extra column depending on access.accessname. Sorry I'm a noob :(
Where are you getting lost on the tutorials? Maybe I can help clarify.
Well I'm not sure if I should be returning anything or do I just literally just do the select in the function and how to actually call my function. Do I store the function somewhere else in the db and just have a call to the function in my view. Or does the function and the call go in to the view? Thanks for your help
The function is defined in the database, and you would replace the call to a view with a call to the function.
Okay I have made some progress but I have ran in to a brick wall as I want to return a varying column table. I am receiving this error "a column definition list is required for functions returning "record"" After doing some research it seems that you have to define the columns which is not really helping me, any ideas?
|

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.