Ansuman Bebarta
Ansuman Bebarta

Reputation: 7256

maximum number of arguments postgresql function can take

I have a view consists of two table. Let's say table TableA and table TableB.

Now table A has got around 20 columns and table B has go 4 columns.

TableA (
  id datatype,
  uid datatype,
  .  
  .   
  .
  18 more);

TableB (
  id datatype,
  uid datatype,
  a_id datatype,
  amount datatype,
  CONSTRAINT tablea_tableb_fkey FOREIGN KEY (a_id)
      REFERENCES tablea (id) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE RESTRICT,
);

So there is one to many relationship between TableA and TableB. Now I have written the view as follows...

CREATE OR REPLACE VIEW AB AS 
 SELECT a.id, a.uid, ..., array_agg(b.amount) AS amounts
   FROM TableA a
   JOIN TableB b ON a.id = b.a_id
  GROUP BY i.id;

Now I want to write insert rule for this view which I am doing by writing a helper function. The function takes around 18 parameters (except id, uid has default value) for inserting into TableA and 1 parameter which is an Array for TableB.

So the total parameters for function is 19. I want to know what is the maximum number of arguments that I can pass to function in postgresql? Is it wise to send this many number of arguments? Is there any better way to write the function for this many number of arguments?

Upvotes: 1

Views: 3601

Answers (1)

Pavel Stehule
Pavel Stehule

Reputation: 45795

FUNC_MAX_ARGS is one compilation parameter (you can change it and recompile), and on my 9.2 source code is 100.

If you have more parameters, then using a arrays is a good idea.

Upvotes: 1

Related Questions