What I am looking for is what I would call a "parametrised view". When looking around on the internet, I learned that that is not supported by PostgreSQL, and that I should use a function instead.
So I create a function:
CREATE OR REPLACE FUNCTION public.student_get_byschool(
_schoolid integer
) RETURNS SETOF student AS
$body$
SELECT * FROM student WHERE schoolid=_schoolid;
$body$
LANGUAGE 'sql';
However, if I want to select a little more of that student by joining other records, my RETURNS clause isn't correct anymore. I could fix that in two ways:
- Use
RETURNS SETOF RECORD, but that seems to have some issues in my C#.NET application, as it doesn't give me any column definitions. - Create a new type that holds all the data that I want to return, but that introduces redundancy which is what I very much want to avoid in my database design.
My question now is, are these the only options, or is more possible. Note that I just started PostgreSQL and C#.NET.
returns table (col1 integer, ...)