Middle+
Have you used anything other than the default index? What is a stored function and procedure?
sobes.tech AI
Answer from AI
Besides default indexes (e.g., B-tree), the following are often used:
- Hash indexes — for fast exact match searches.
- GIN and GiST indexes — for full-text search and working with arrays in PostgreSQL.
- Bitmap indexes — for columns with a small number of unique values.
Stored procedure — a set of SQL commands stored in the database and executed as a single unit. It can accept parameters, perform complex logic, and modify data.
Stored function — similar to a procedure but always returns a value and can be used in SQL queries, for example, in SELECT.
Example of a stored function in SQL:
CREATE FUNCTION get_user_count() RETURNS integer AS $$
BEGIN
RETURN (SELECT COUNT(*) FROM users);
END;
$$ LANGUAGE plpgsql;