Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2012
    Posts
    1

    Unanswered: If you want to discard the results of a SELECT, use PERFORM instead

    simple query returns error "If you want to discard the results of a SELECT, use PERFORM instead."

    CREATE OR REPLACE FUNCTION mydb.sp_getSupId(p_userId integer)
    RETURNS integer AS
    $BODY$
    DECLARE

    BEGIN

    select ts.table1_id from mydb.timesheet ts where ts.user_id = p_userId;

    select st.table2_id from mydb.timesheet_subrecs st where st.timesheet_id = ts.table1_id;

    select rast.supId from mydb.sub_task rast where rast.subtask_id = st.table2_id;

    return rast.supId;

    I have tried a number of ways to employ "perform" but none work without error in syntax

  2. #2
    Join Date
    May 2008
    Posts
    277
    But you are not discarding the results of the SELECT, you're returning it as the result of the function. Combine your three queries into one using JOINS, and then select the result into a variable.

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    This should do it:
    Code:
    CREATE OR REPLACE FUNCTION mydb.sp_getSupId(p_userId integer)
      RETURNS integer AS
      language SQL
    $BODY$
    select rast.supId 
      from mydb.sub_task rast 
        join mydb.timesheet_subrecs st ON rast.subtask_id = st.table2_id
        join mydb.timesheet ts on st.timesheet_id = ts.table1_id
      where ts.user_id = p_userId;
    $BODY$
    ;
    Note that if the join returns more than one row, only the first value will be returned.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •