Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7uXz-0003s2-Oa for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Jul 2022 08:01:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7uXx-0000Q3-Gi for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Jul 2022 08:01:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7uXw-0000Pu-Re for pgsql-hackers@lists.postgresql.org; Sun, 03 Jul 2022 08:01:37 +0000 Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o7uXs-0007MX-CO for pgsql-hackers@lists.postgresql.org; Sun, 03 Jul 2022 08:01:35 +0000 Received: by mail-qt1-x82a.google.com with SMTP id z13so5784461qts.12 for ; Sun, 03 Jul 2022 01:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ltrEfGUSD+15Zar2qxxrax94VVy/dnz0RQAaXTGpNBM=; b=ekWTTxZ7ugh2Kq4Hh6iXAdA6JOsEwuiJCfmPHh6Uazr4+h76eQehXIWg3d0e2OcQm8 iFeU+tkAmiecQoy+Y/+TeK8UG/oBHWu2HlBAjiCWYd02PDJHlfTl/93D75pg17NGaxOq akDwBnDaj6trBP6OH8H1cWMcLBcsOHvNQE1j0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ltrEfGUSD+15Zar2qxxrax94VVy/dnz0RQAaXTGpNBM=; b=VV7LzyZte+bl/K2nX3j9ftJU42pL44FOLHaSLVO+opT00U95Lc2pFPCZ0IDvmJSFCr OAJBaKDDofv5/Y61AqidKzONKSOuVWPRYoA2mzmtBsLPfegI/MEcD5QZtWv/Z2Qqgtqm zBT3mw7u4wl/iOMm+/UBgUhTFzXWEIJz9S8ipcOBQQ/NV4sb9Fq2Ji4QvlEzqgFQCVZ3 v2NYDJQwTCm0kNskd2hjSssfYGyJpiPcKDVEYkzZ67d4vAjCpP5/vMte/TT1LWVj1jUJ 20Ze1IE77CBqWZbGLTUNWrtJy1/4yta60ubMMpd0nzCsO7AWl4P3WE14dYv4xx/MFORq idXw== X-Gm-Message-State: AJIora8AfqxuhlcvFUK1M/J0ZlX+4BQQR5cEaRzoLbIC+Dv0C9hqGnkM zjoLxoY7kxnbDFQpYWi++cpZxg== X-Google-Smtp-Source: AGRyM1ukPvHgDNQDhZYtHMrbjLM7PQBhwU9Azppk9XSXKZ0tG2+EjfAQkL88tEK6DHzZT1jcoeIlXA== X-Received: by 2002:a05:6214:2488:b0:470:b46d:c0c5 with SMTP id gi8-20020a056214248800b00470b46dc0c5mr22870157qvb.120.1656835290723; Sun, 03 Jul 2022 01:01:30 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id b126-20020a376784000000b006a760ce8a37sm22449946qkc.45.2022.07.03.01.01.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jul 2022 01:01:29 -0700 (PDT) Date: Sun, 3 Jul 2022 01:01:27 -0700 From: Noah Misch To: Tom Lane Cc: Michael Meskes , pgsql-hackers@lists.postgresql.org Subject: Re: SQL/JSON functions vs. ECPG vs. STRING as a reserved word Message-ID: <20220703080127.GA2476530@rfd.leadboat.com> References: <3661437.1653855582@sss.pgh.pa.us> <4158666.1653945615@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4158666.1653945615@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, May 30, 2022 at 05:20:15PM -0400, Tom Lane wrote: [allow EXEC SQL TYPE unreserved_keyword IS ...] > 1. In pgc.l, if an identifier is a typedef name, ignore any possible > keyword meaning and return it as an IDENT. (I'd originally supposed > that we'd want to return some new TYPEDEF token type, but that does > not seem to be necessary right now, and adding a new token type would > increase the patch footprint quite a bit.) > > 2. In the var_type production, forget about ECPGColLabel[Common] > and just handle the keywords we know we need, plus IDENT for the > typedef case. It turns out that we have to have duplicate coding > because most of these keywords are not keywords in C lexing mode, > so that they'll come through the IDENT path anyway when we're > in a C rather than SQL context. That seemed acceptable to me. > I thought about adding them all to the C keywords list but that > seemed likely to have undesirable side-effects, and again it'd > bloat the patch footprint. > > This fix is not without downsides. Disabling recognition of > keywords that match typedefs means that, for example, if you > declare a typedef named "work" then ECPG will fail to parse > "EXEC SQL BEGIN WORK". So in a real sense this is just trading > one hazard for another. But there is an important difference: > with this, whether your ECPG program works depends only on what > typedef names and SQL commands are used in the program. If > it compiles today it'll still compile next year, whereas with > the present implementation the addition of some new unreserved > SQL keyword could break it. We'd have to document this change > for sure, and it wouldn't be something to back-patch, but it > seems like it might be acceptable from the users' standpoint. I agree this change is more likely to please a user than to harm a user. The user benefit is slim, but the patch is also slim. > We could narrow (not eliminate) this hazard if we could get the > typedef lookup in pgc.l to happen only when we're about to parse > a var_type construct. But because of Bison's lookahead behavior, > that seems to be impossible, or at least undesirably messy > and fragile. But perhaps somebody else will see a way. I don't, though I'm not much of a Bison wizard. > Anyway, this seems like too big a change to consider for v15, > so I'll stick this patch into the v16 CF queue. It's only > draft quality anyway --- lacks documentation changes and test > cases. There are also some coding points that could use review. > Notably, I made the typedef lookup override SQL keywords but > not C keywords; this is for consistency with the C-mode lookup > rules, but is it the right thing? That decision seems fine. ScanCKeywordLookup() covers just twenty-six keywords, and that list hasn't changed since 2003. Moreover, most of them are keywords of the C language itself, so allowing them would entailing mangling them in the generated C to avoid C compiler errors. Given the lack of complaints, let's not go there. I didn't locate any problems beyond the test and doc gaps that you mentioned, so I've marked this Ready for Committer.