pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedfunction signature allow "default" keyword
5+ messages / 4 participants
[nested] [flat]
* function signature allow "default" keyword
@ 2023-05-15 08:33 jian he <jian.universality@gmail.com>
2023-05-15 09:00 ` Re: function signature allow "default" keyword Thomas Kellerer <shammat@gmx.net>
2023-05-16 13:12 ` Re: function signature allow "default" keyword Peter Eisentraut <peter.eisentraut@enterprisedb.com>
0 siblings, 2 replies; 5+ messages in thread
From: jian he @ 2023-05-15 08:33 UTC (permalink / raw)
To: pgsql-general list <pgsql-general@lists.postgresql.org>
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: function signature allow "default" keyword
2023-05-15 08:33 function signature allow "default" keyword jian he <jian.universality@gmail.com>
@ 2023-05-15 09:00 ` Thomas Kellerer <shammat@gmx.net>
2023-05-16 03:11 ` Re: function signature allow "default" keyword jian he <jian.universality@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Thomas Kellerer @ 2023-05-15 09:00 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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);
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: function signature allow "default" keyword
2023-05-15 08:33 function signature allow "default" keyword jian he <jian.universality@gmail.com>
2023-05-15 09:00 ` Re: function signature allow "default" keyword Thomas Kellerer <shammat@gmx.net>
@ 2023-05-16 03:11 ` jian he <jian.universality@gmail.com>
2023-05-16 04:26 ` Re: function signature allow "default" keyword Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: jian he @ 2023-05-16 03:11 UTC (permalink / raw)
To: Thomas Kellerer <shammat@gmx.net>; +Cc: pgsql-general@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: function signature allow "default" keyword
2023-05-15 08:33 function signature allow "default" keyword jian he <jian.universality@gmail.com>
2023-05-15 09:00 ` Re: function signature allow "default" keyword Thomas Kellerer <shammat@gmx.net>
2023-05-16 03:11 ` Re: function signature allow "default" keyword jian he <jian.universality@gmail.com>
@ 2023-05-16 04:26 ` Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Pavel Stehule @ 2023-05-16 04:26 UTC (permalink / raw)
To: jian he <jian.universality@gmail.com>; +Cc: Thomas Kellerer <shammat@gmx.net>; pgsql-general@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: function signature allow "default" keyword
2023-05-15 08:33 function signature allow "default" keyword jian he <jian.universality@gmail.com>
@ 2023-05-16 13:12 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
1 sibling, 0 replies; 5+ messages in thread
From: Peter Eisentraut @ 2023-05-16 13:12 UTC (permalink / raw)
To: jian he <jian.universality@gmail.com>; pgsql-general list <pgsql-general@lists.postgresql.org>
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2023-05-16 13:12 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15 08:33 function signature allow "default" keyword jian he <jian.universality@gmail.com>
2023-05-15 09:00 ` Thomas Kellerer <shammat@gmx.net>
2023-05-16 03:11 ` jian he <jian.universality@gmail.com>
2023-05-16 04:26 ` Pavel Stehule <pavel.stehule@gmail.com>
2023-05-16 13:12 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox