Take the following query:
CREATE TEMP TABLE users
(
user_id SERIAL,
name varchar(50)
);
CREATE TEMP TABLE admins
(
section integer
) INHERITS(users);
INSERT INTO users (name) VALUES ('Kevin');
INSERT INTO admins (name, section) VALUES ('John', 1);
CREATE FUNCTION pg_temp.is_admin(INTEGER) RETURNS BOOLEAN AS
$$
DECLARE
result boolean;
BEGIN
SELECT INTO result COUNT(*) > 0
FROM admins
WHERE user_id = $1;
RETURN result;
END;
$$
LANGUAGE PLPGSQL;
SELECT name, pg_temp.is_admin(user_id) FROM users;
Is there any postgres feature that would allow me to get rid of the is_admin function? Basically to check the row class type (in terms of inheritance)?
I understand the table design isn't ideal, this is just to provide a simple example so I can find out if what I am after is possible.