public inbox for [email protected]help / color / mirror / Atom feed
Re: Declaring a field that is also an out parameter in a function 5+ messages / 3 participants [nested] [flat]
* Re: Declaring a field that is also an out parameter in a function @ 2024-07-07 07:31 Pavel Stehule <[email protected]> 0 siblings, 2 replies; 5+ messages in thread From: Pavel Stehule @ 2024-07-07 07:31 UTC (permalink / raw) To: Tom Lane <[email protected]>; +Cc: Michael Nolan <[email protected]>; pgsql-general ne 7. 7. 2024 v 0:14 odesílatel Tom Lane <[email protected]> napsal: > Michael Nolan <[email protected]> writes: > > Shouldn't declaring a field that is also an OUT parameter throw an error? > > No. The DECLARE is a block nested within the function, > and the parameter is declared at function scope. > So this is a standard case of an inner declaration masking > an outer one. > > Possibly plpgsql_check can be set to complain about such cases, > but they're legal according to the language specification. > yes, it does (2024-07-07 09:27:14) postgres=# select * from plpgsql_check_function('test_function'); ┌───────────────────────────────────────────────────────────────┐ │ plpgsql_check_function │ ╞═══════════════════════════════════════════════════════════════╡ │ warning:00000:10:statement block:parameter "d3" is overlapped │ │ Detail: Local variable overlap function parameter. │ │ warning extra:00000:8:DECLARE:never read variable "d3" │ │ warning extra:00000:unused parameter "$1" │ │ warning extra:00000:unused parameter "$2" │ │ warning extra:00000:unused parameter "$3" │ │ warning extra:00000:unmodified OUT variable "d3" │ └───────────────────────────────────────────────────────────────┘ (7 rows) but looks so there are false alarms related to using an alias. It is interesting so I have not any report about this issue, so probably using aliases is not too common today. Regards Pavel > > regards, tom lane > > > ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Declaring a field that is also an out parameter in a function @ 2024-07-07 09:13 Pavel Stehule <[email protected]> parent: Pavel Stehule <[email protected]> 1 sibling, 1 reply; 5+ messages in thread From: Pavel Stehule @ 2024-07-07 09:13 UTC (permalink / raw) To: Tom Lane <[email protected]>; +Cc: Michael Nolan <[email protected]>; pgsql-general ne 7. 7. 2024 v 9:31 odesílatel Pavel Stehule <[email protected]> napsal: > > > ne 7. 7. 2024 v 0:14 odesílatel Tom Lane <[email protected]> napsal: > >> Michael Nolan <[email protected]> writes: >> > Shouldn't declaring a field that is also an OUT parameter throw an >> error? >> >> No. The DECLARE is a block nested within the function, >> and the parameter is declared at function scope. >> So this is a standard case of an inner declaration masking >> an outer one. >> >> Possibly plpgsql_check can be set to complain about such cases, >> but they're legal according to the language specification. >> > > yes, it does > > (2024-07-07 09:27:14) postgres=# select * from > plpgsql_check_function('test_function'); > ┌───────────────────────────────────────────────────────────────┐ > │ plpgsql_check_function │ > ╞═══════════════════════════════════════════════════════════════╡ > │ warning:00000:10:statement block:parameter "d3" is overlapped │ > │ Detail: Local variable overlap function parameter. │ > │ warning extra:00000:8:DECLARE:never read variable "d3" │ > │ warning extra:00000:unused parameter "$1" │ > │ warning extra:00000:unused parameter "$2" │ > │ warning extra:00000:unused parameter "$3" │ > │ warning extra:00000:unmodified OUT variable "d3" │ > └───────────────────────────────────────────────────────────────┘ > (7 rows) > > but looks so there are false alarms related to using an alias. It is > interesting so I have not any report about this issue, so probably using > aliases is not too common today. > I was blind, plpgsql_check is correct Regards Pavel > > Regards > > Pavel > > >> >> regards, tom lane >> >> >> ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Declaring a field that is also an out parameter in a function @ 2024-07-07 13:01 Michael Nolan <[email protected]> parent: Pavel Stehule <[email protected]> 0 siblings, 1 reply; 5+ messages in thread From: Michael Nolan @ 2024-07-07 13:01 UTC (permalink / raw) To: Pavel Stehule <[email protected]>; +Cc: Tom Lane <[email protected]>; pgsql-general On Sun, Jul 7, 2024 at 4:13 AM Pavel Stehule <[email protected]> wrote: > > but looks so there are false alarms related to using an alias. It is interesting so I have not any report about this issue, so probably using aliases is not too common today. I'm not sure why there's a warning about using an alias. 43.3.1 says to use them for improved readability. Mike Nolan ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Declaring a field that is also an out parameter in a function @ 2024-07-07 14:37 Tom Lane <[email protected]> parent: Pavel Stehule <[email protected]> 1 sibling, 0 replies; 5+ messages in thread From: Tom Lane @ 2024-07-07 14:37 UTC (permalink / raw) To: Pavel Stehule <[email protected]>; +Cc: Michael Nolan <[email protected]>; pgsql-general Pavel Stehule <[email protected]> writes: > (2024-07-07 09:27:14) postgres=# select * from > plpgsql_check_function('test_function'); > ┌───────────────────────────────────────────────────────────────┐ > │ plpgsql_check_function │ > ╞═══════════════════════════════════════════════════════════════╡ > │ warning:00000:10:statement block:parameter "d3" is overlapped │ > │ Detail: Local variable overlap function parameter. │ Nice! FWIW, I think the standard terminology is "local variable shadows function parameter". regards, tom lane ^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Declaring a field that is also an out parameter in a function @ 2024-07-07 14:42 Pavel Stehule <[email protected]> parent: Michael Nolan <[email protected]> 0 siblings, 0 replies; 5+ messages in thread From: Pavel Stehule @ 2024-07-07 14:42 UTC (permalink / raw) To: Michael Nolan <[email protected]>; +Cc: Tom Lane <[email protected]>; pgsql-general ne 7. 7. 2024 v 15:01 odesílatel Michael Nolan <[email protected]> napsal: > On Sun, Jul 7, 2024 at 4:13 AM Pavel Stehule <[email protected]> > wrote: > > > > but looks so there are false alarms related to using an alias. It is > interesting so I have not any report about this issue, so probably using > aliases is not too common today. > > I'm not sure why there's a warning about using an alias. 43.3.1 says > to use them for improved readability. > it is obsolete - aliases were used when Postgres doesn't support named arguments. I don't know any good reason why one variable can use more than one name. There can be an exception when argument names are very long, but generally they are not used. > > Mike Nolan > ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2024-07-07 14:42 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2024-07-07 07:31 Re: Declaring a field that is also an out parameter in a function Pavel Stehule <[email protected]> 2024-07-07 09:13 ` Pavel Stehule <[email protected]> 2024-07-07 13:01 ` Michael Nolan <[email protected]> 2024-07-07 14:42 ` Pavel Stehule <[email protected]> 2024-07-07 14:37 ` Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox