On Fri, Jan 20, 2023 at 9:17 AM Gurjeet Singh <gurjeet@singh.im> wrote:
On Sat, Jan 14, 2023 at 6:14 AM Gurjeet Singh <gurjeet@singh.im> wrote: > > I agree that an identifier _surrounded_ by the same token (e.g. #foo#) > or the pairing token (e.g. {foo}) looks better aesthetically, so I am > okay with any of the following variations of the scheme, as well: > > \#foo\# (tested; works) > \#foo# (not tested; reduces ident length by 1) > > We can choose a different character, instead of #. Perhaps \{foo} !
Please find attached the patch that uses \{foo} styled Named Operators. This is in line with Tom's reluctant hint at possibly using curly braces as delimiter characters. Since the curly braces are used by the SQL Specification for row pattern recognition, this patch proposes escaping the first of the curly braces.
We can get rid of the leading backslash, if (a) we're confident that SQL committee will not use curly braces anywhere else, and (b) if we're confident that if/when Postgres supports Row Pattern Recognition feature, we'll be able to treat curly braces inside the PATTERN clause specially. Since both of those conditions are unlikely, I think we must settle for the escaped-first-curly-brace style for the naming our operators.
Keeping with the previous posts, here's a sample SQL script showing what the proposed syntax will look like in action. Personally, I prefer the \#foo style, since the \# prefix stands out among the text, better than \{..} does, and because # character is a better signal of an operator than {.
create operator \{add_point} (function = box_add, leftarg = box, rightarg = point); create table test(a box); insert into test values('((0,0),(1,1))'), ('((0,0),(2,1))'); select a as original, a \{add_point} '(1,1)' as modified from test; drop operator \{add_point}(box, point);