I have a bunch of funcs (or procs) for simple inserts, ex: insert_user( email );
Most of them return the inserted_id, whether it's for other procs or a driver. And some don't, like inserts to many-many tables with no id.
PG stored procs have out params that seem to be treated the SQL Standard way and not like PG funcs. they're not optional/defaultable, so you end up with a trailing null every time you don't need the id, ex:
call insert_user('test@email', null);
That feels clunky. If I could overload it that'd be awesome, but surprisingly you can't with the out params, even though they're a required part of the signature. I could make a second proc for every insert, like:
call insert_user( 'test@email' );
call insert_user_return_id( 'test@email', out_id);
But then I have double the procs to test and maintain. I could switch to functions, which won't require an extra argument for the out_id, and I can ignore the out_id if I don't want it. But the "insert" funcs have to start with SELECT ex:
select insert_user( 'test@email' );
select insert_user( 'test@email' ) into out_id;
select id from insert_user( 'test@email' );
And something about "select insert" feels uncomfortable. Especially with many-many inserts that return void. Any thoughts or advice would be greatly appreciated!