Thread
-
function signature allow "default" keyword
jian he <jian.universality@gmail.com> — 2023-05-15T08:33:53Z
function idea. allow function calling using the default keyword for any of the input arguments. example: https://dbfiddle.uk/FQwnfdmm So something like this "SELECT * FROM customer_orders(2579927, 'order_placed_on DESC', default, 2);" should work.
-
Re: function signature allow "default" keyword
shammat@gmx.net — 2023-05-15T09:00:40Z
jian he schrieb am 15.05.2023 um 10:33: > > function idea. > allow function calling using the default keyword for any of the input arguments. > > example: https://dbfiddle.uk/FQwnfdmm > So something like this "SELECT * FROM customer_orders(2579927, 'order_placed_on DESC', default, 2);" > should work. You can use named parameters when calling the function, that will use the default value for those not mentioned: SELECT * FROM customer_orders(_customer_id => 2579927, _sort_field_and_direction => 'order_placed_on DESC', _offset => 2); -
Re: function signature allow "default" keyword
jian he <jian.universality@gmail.com> — 2023-05-16T03:11:30Z
On Mon, May 15, 2023 at 5:00 PM Thomas Kellerer <shammat@gmx.net> wrote: > jian he schrieb am 15.05.2023 um 10:33: > > > > function idea. > > allow function calling using the default keyword for any of the input > arguments. > > > > example: https://dbfiddle.uk/FQwnfdmm > > So something like this "SELECT * FROM customer_orders(2579927, > 'order_placed_on DESC', default, 2);" > > should work. > > > You can use named parameters when calling the function, that will use the > default value for those not mentioned: > > SELECT * > FROM customer_orders(_customer_id => 2579927, > _sort_field_and_direction => 'order_placed_on DESC', > _offset => 2); > > > > select proname ,proargtypes ,pg_get_expr(pp.proargdefaults,0,true) ,pronargdefaults from pg_proc pp where pp.proname = 'customer_orders'; ----------return------------- proname | customer_orders proargtypes | 23 25 23 23 1082 1082 pg_get_expr | 10, 0, CURRENT_DATE - 30, CURRENT_DATE pronargdefaults | 4 table insert works, i guess because pg_attribute has column ordinal number (left to right). but pg_proc only counts the number of arguments that have a default value. -
Re: function signature allow "default" keyword
Pavel Stehule <pavel.stehule@gmail.com> — 2023-05-16T04:26:45Z
Hi út 16. 5. 2023 v 5:11 odesílatel jian he <jian.universality@gmail.com> napsal: > > > On Mon, May 15, 2023 at 5:00 PM Thomas Kellerer <shammat@gmx.net> wrote: > >> jian he schrieb am 15.05.2023 um 10:33: >> > >> > function idea. >> > allow function calling using the default keyword for any of the input >> arguments. >> > >> > example: https://dbfiddle.uk/FQwnfdmm >> > So something like this "SELECT * FROM customer_orders(2579927, >> 'order_placed_on DESC', default, 2);" >> > should work. >> >> >> You can use named parameters when calling the function, that will use the >> default value for those not mentioned: >> >> SELECT * >> FROM customer_orders(_customer_id => 2579927, >> _sort_field_and_direction => 'order_placed_on DESC', >> _offset => 2); >> >> >> >> > > select proname > ,proargtypes > ,pg_get_expr(pp.proargdefaults,0,true) > ,pronargdefaults > from pg_proc pp > where pp.proname = 'customer_orders'; > ----------return------------- > proname | customer_orders > proargtypes | 23 25 23 23 1082 1082 > pg_get_expr | 10, 0, CURRENT_DATE - 30, CURRENT_DATE > pronargdefaults | 4 > > table insert works, i guess because pg_attribute has column ordinal number > (left to right). > but pg_proc only counts the number of arguments that have a default value. > The tables don't support overloading. I cannot to have tab1(a int, b int), tab1(a int, b int, c int) but I can have proc1(int, int), proc1(int, int, int) Regards Pavel
-
Re: function signature allow "default" keyword
Peter Eisentraut <peter.eisentraut@enterprisedb.com> — 2023-05-16T13:12:19Z
On 15.05.23 10:33, jian he wrote: > function idea. > allow function calling using the default keyword for any of the input > arguments. > > example: https://dbfiddle.uk/FQwnfdmm <https://dbfiddle.uk/FQwnfdmm> > So something like this "SELECT * FROM customer_orders(2579927, > 'order_placed_on DESC', default, 2);" > should work. This is currently not supported by PostgreSQL. I have half a patch for it, though, so maybe we'll get to it one day.