1
votes

This function is based on a Oracle PL/SQL Function:

  create or replace FUNCTION SP_ComputeEntity (P_ENTITY NUMERIC, P_CAMPAIGN  NUMERIC, P_COMPLETE_IF  NUMERIC, P_COMPUTE_MODE  NUMERIC ) RETURNS VOID AS $$
DECLARE
  [..]


-- This is the list of the entity's subordinates
  [..]

-- This is the list of the entity's questionnaires
 [..]

BEGIN

  -- If the entity must not be computed for this campaign stop
 [..]
  -- Check if already computed .
 [..]

  -- If not already computed compute it now .
  IF V_EXISTS = 0 THEN

    -- Loop on subordinates to check if already computed
    OPEN ENTITY_COLUMNS;
    LOOP
      FETCH ENTITY_COLUMNS INTO V_COLUMN_ID;
      EXIT WHEN ENTITY_COLUMNS%NOTFOUND;

      SP_ComputeEntity(V_COLUMN_ID, P_CAMPAIGN, P_COMPLETE_IF, P_COMPUTE_MODE);

    END LOOP;
    CLOSE ENTITY_COLUMNS;

    [..]
END;
$$
LANGUAGE plpgsql;

My problem is that pgAdmin III gives me ERROR: syntax error at or near "SP_ComputeEntity" SQL state: 42601 Character: 1773 and I don't know why. Can it be done? Can someone call in a function the same function in postgresql?

3

3 Answers

2
votes

If you don't need a result from the query, you can use Perform

PERFORM SP_ComputeEntity(V_COLUMN_ID, P_CAMPAIGN, P_COMPLETE_IF, P_COMPUTE_MODE);
0
votes

Execute SP_ComputeEntity procedure like

 SELECT SP_ComputeEntity(V_COLUMN_ID, P_CAMPAIGN, P_COMPLETE_IF, P_COMPUTE_MODE);
0
votes

You can also use your function just like a select and retrive results in variables.

Just for example:

SELECT INTO myvar myres FROM myfunction(param1, param2);