Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Side-effects in functions
Invoking functions

Instruction

Cool! As we just learned, there are a few ways of calling a function:

  • Using a SELECT statement. You can use a regular SELECT in SQL (not in PL/pgSQL):
    SELECT add_topic('Quick cakes');
  • In PL/pgSQL, you can:
    • Use the SELECT INTO syntax to save a query result:
      SELECT thumbs_up, thumbs_down
      INTO upvotes, downvotes
      FROM post
      WHERE id = post_id
      
    • Use assignment to save the query result:
      post_id := (
        SELECT post_id
        FROM post
        WHERE user_id = 17
        LIMIT 1
      );
      
    • Use assignment to invoke a function:
      user_id := get_most_active_user();
    • PERFORM statement (in PL/pgSQL).
      PERFORM add_topic('Quick cakes');

Exercise

Click Next exercise to jump to the next part where we're going to continue our adventure with complex functions!