tag:blogger.com,1999:blog-8839574367290288724.post801017107631287494..comments2023-12-11T13:13:11.330-08:00Comments on Pavel Stehule's blog: don't use SQL keywords as PLpgSQL variable namesPavel Stěhulehttp://www.blogger.com/profile/01996484227228696817noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8839574367290288724.post-9504281870819926242019-03-02T12:20:47.243-08:002019-03-02T12:20:47.243-08:00Good observationGood observationAnonymoushttps://www.blogger.com/profile/05093654987909396513noreply@blogger.comtag:blogger.com,1999:blog-8839574367290288724.post-32375209857979465212019-03-01T21:04:10.202-08:002019-03-01T21:04:10.202-08:00ok. I tested using labels, and it is working too. ...ok. I tested using labels, and it is working too. <br /><br />postgres=# create or replace function foo(a int)<br />returns int as $$<br /><<main>><br />declare offset int = 10;<br />begin<br /> return 1 + main.offset + a;<br />end;<br />$$ language plpgsql;Pavel Stěhulehttps://www.blogger.com/profile/01996484227228696817noreply@blogger.comtag:blogger.com,1999:blog-8839574367290288724.post-16569497861677417972019-03-01T16:36:44.810-08:002019-03-01T16:36:44.810-08:00@pavel
I totally agree with you, and I suggest the...@pavel<br />I totally agree with you, and I suggest the same thing you say, but the clients of some migrations from oracle are ...Anonymoushttps://www.blogger.com/profile/05093654987909396513noreply@blogger.comtag:blogger.com,1999:blog-8839574367290288724.post-668674055971105192019-03-01T08:14:09.714-08:002019-03-01T08:14:09.714-08:00@Anthony
yes, it can works. What I known, it is n...@Anthony<br /><br />yes, it can works. What I known, it is not officially supported feature - but it is working. Still better to use different name or some prefix.Pavel Stěhulehttps://www.blogger.com/profile/01996484227228696817noreply@blogger.comtag:blogger.com,1999:blog-8839574367290288724.post-86879529237059276702019-03-01T06:05:41.560-08:002019-03-01T06:05:41.560-08:00i love plpgsql check, thanks for yuor work,
i neve...i love plpgsql check, thanks for yuor work,<br />i never use key word, but when i find it in some client code i put double quote ""<br /><br />CREATE OR REPLACE FUNCTION public.fx()<br /> RETURNS integer<br /> LANGUAGE plpgsql<br />AS $function$<br />DECLARE "offset" int DEFAULT 0;<br />BEGIN<br /> RETURN "offset" + 1;<br />END;<br /><br />mia=# select fx();<br /> fx <br />----<br /> 1<br />(1 fila)<br /><br />$function$<br /><br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8839574367290288724.post-86118393406677366622019-03-01T04:54:35.813-08:002019-03-01T04:54:35.813-08:00This is result of plpgsql_check_function for this ...This is result of plpgsql_check_function for this case<br /><br />postgres=# select * from plpgsql_check_function('foo');<br />┌───────────────────────────────────────────────────────────────────────────────┐<br />│ plpgsql_check_function │<br />╞═══════════════════════════════════════════════════════════════════════════════╡<br />│ warning:00000:3:statement block:name of variable "offset" is reserved keyword │<br />│ Detail: The reserved keyword was used as variable name. │<br />│ error:42601:4:RETURN:query "SELECT offset + foo(a)" returned 0 columns │<br />└───────────────────────────────────────────────────────────────────────────────┘<br />(3 rows)<br />Pavel Stěhulehttps://www.blogger.com/profile/01996484227228696817noreply@blogger.comtag:blogger.com,1999:blog-8839574367290288724.post-67436866198345924262019-03-01T01:43:02.888-08:002019-03-01T01:43:02.888-08:00Should plpgsql parser check this case and produce ...Should plpgsql parser check this case and produce error, e.g. "ambiguous variable name detected" or whatever?Pavlo Golubhttps://www.blogger.com/profile/03137289277361291519noreply@blogger.com