Question

I have table "Table1" and SQL procedure "testProc" which accepts argument of type "Table1". When this procedure gets invoked like this:

select testProc(t.*) from Table1 t; 

is PostgreSQL internally using pointers for passing that argument? Or is it copied in memory for each row?

Thanks!

Was it helpful?

Solution

There are two distinct cases here, one must involve a copy, and the second must involve pointers.

In the case you are mentioning a copy is made. You can test this like so:

create function test_test(inout test test) returns test as 
$$
begin
   $1.test := $1.test + 1;
   return;
end;
$$ language plpgsql;

select (test_test(t)).test, (test_test(t)).test from test t;

where test.test is an integer. The numbers will be the same.

The second is in triggers, where modifying NEW will be passed to the next trigger. These must be passed by reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top