Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: support named arguments for routines #122264

Open
DrewKimball opened this issue Apr 12, 2024 · 0 comments
Open

sql: support named arguments for routines #122264

DrewKimball opened this issue Apr 12, 2024 · 0 comments
Labels
A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-known-limitation O-qa T-sql-queries SQL Queries Team

Comments

@DrewKimball
Copy link
Collaborator

DrewKimball commented Apr 12, 2024

In addition to the usual positional notation, postgres allows a routine to be invoked with named arguments:

postgres=# create function foo (a int, b int) returns int language sql as $$ select a; $$;
CREATE FUNCTION

-- Positional args
postgres=# select foo(1, 2);
 foo
-----
   1
(1 row)

-- Named args in usual order
postgres=# select foo(a => 1, b => 2);
 foo
-----
   1
(1 row)

-- Named args in reverse order
postgres=# select foo(b => 1, a => 2);
 foo
-----
   2
(1 row)

It's also possible to use := instead of =>:

postgres=# select foo(b := 1, a := 2);
 foo
-----
   2
(1 row)

Finally, named and positional notation can be used together, as long as named arguments follow all positional arguments:

postgres=# create function foo (a int, b int default 200, c int default 300) returns int language sql as $$ select b; $$;
CREATE FUNCTION

postgres=# select foo(1, 2);
 foo
-----
   2
(1 row)

postgres=# select foo(1, c => 2);
 foo
-----
 200
(1 row)

postgres=# select foo(1, c => 2, b => -1);
 foo
-----
  -1
(1 row)

PG docs: https://www.postgresql.org/docs/current/sql-syntax-calling-funcs.html#SQL-SYNTAX-CALLING-FUNCS-NAMED

Jira issue: CRDB-37780

@DrewKimball DrewKimball added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-known-limitation O-qa T-sql-queries SQL Queries Team A-sql-routine UDFs and Stored Procedures labels Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-known-limitation O-qa T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

1 participant