Christian Thomsen <c...@cs.aau.dk> writes: > I have created a set-returning C function and a view that selects all > the returned rows. When I use SELECT * FROM theview, the returned rows > look fine. But if I use, e.g., SELECT count(*) FROM theview or SELECT > sum(a) FROM theview, I get a segmentation fault.
> LOG: server process (PID 7099) was terminated by signal 11: > Segmentation fault > Is this a bug? Yeah, in your code: you've violated multiple rules about set-returning functions. Offhand: * using expectedDesc without checking for NULL * creating the tuplestore in the wrong context * failing to set setDesc Also, blindly using expectedDesc instead of constructing your own tuple descriptor is rather badly missing the point. This code will *only* work for a tupdesc consisting of some number of integer columns; if you're passed something else it will fail in more or less horrible ways. What you're supposed to do is construct a tupdesc that accurately describes what you're returning, and use that for the tupstore and pass it back as setDesc. Then the core code can verify it matches expectedDesc. Passing in expectedDesc is only useful for functions that can work with a variety of actual output tupledescriptors. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers