Re: Default values in functions

2021-12-29 Thread Michael Lewis
On Wed, Dec 29, 2021, 5:31 PM Tom Lane wrote: > The way to do that is to use named parameters and the associated > call syntax, ie something like > > select myfunc(param1 => 42, param3 => 99); > Thanks very much. I have not seen that before. >

Re: Default values in functions

2021-12-29 Thread Tom Lane
Michael Lewis writes: > Thanks sir. It seems unfortunate that there is not a way to indicate > absence of the third parameter if I need to set a value for the fourth > parameter. The way to do that is to use named parameters and the associated call syntax, ie something like select myfunc(param1

Re: Default values in functions

2021-12-29 Thread Tom Lane
Michael Lewis writes: > Understood. My hope is to pass a parameter that gets overridden by the > default so that I can pass other parameters that come after. As David explained, function parameters don't work that way. You could mechanize something like substitute-a-default-for- null-input, but y

Re: Default values in functions

2021-12-29 Thread Michael Lewis
On Wed, Dec 29, 2021, 4:31 PM Tom Lane wrote: > You didn't say what icount() is, but if it's the one from > contrib/intarray, it's STRICT meaning it'll return NULL, > not zero, for a null array input. Thanks for that. Very good to know. (Or IOW, null::int[] is not at all the same thing as arra

Re: Default values in functions

2021-12-29 Thread Michael Lewis
On Wed, Dec 29, 2021, 4:34 PM David G. Johnston wrote: > That isn’t how it works. Absence is what is important. Null is not > absence. As you showed, if you want nulls to be converted to defaults you > can use coalesce. > Thanks sir. It seems unfortunate that there is not a way to indicate ab

Re: Default values in functions

2021-12-29 Thread David G. Johnston
On Wednesday, December 29, 2021, Michael Lewis wrote: > > > If I can somehow pass "use default for this parameter" to functions like I > can for insert statements, then that would be great to know. > > There is not. > > Generally, the use case I am looking at is having a function with a few > re

Re: Default values in functions

2021-12-29 Thread Tom Lane
Michael Lewis writes: > I am on PG 13.4 and found some surprising behavior with default values. Can > anyone give insight why the last two cases (especially the last one) do not > give the result I expected? If I uncomment the line to set pArrayToCheck > with coalesce, then it gives the expected r

Default values in functions

2021-12-29 Thread Michael Lewis
I am on PG 13.4 and found some surprising behavior with default values. Can anyone give insight why the last two cases (especially the last one) do not give the result I expected? If I uncomment the line to set pArrayToCheck with coalesce, then it gives the expected results though. If I can someho