Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZHMr-0003XP-H8 for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2018 14:28:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZHMq-00072G-SX for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2018 14:28:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eZHMq-000726-Ho for pgsql-hackers@lists.postgresql.org; Wed, 10 Jan 2018 14:28:36 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eZHMm-0001pD-Bu for pgsql-hackers@postgresql.org; Wed, 10 Jan 2018 14:28:35 +0000 Received: by mail-wr0-x241.google.com with SMTP id 100so1553830wrb.7 for ; Wed, 10 Jan 2018 06:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=H/DjhFczaFNK9nZ317XhMDN4HkjytZIw2G1X+5F/vl4=; b=kDPCDz6YxkY4mI0rwMgUPiM8wmO/YkBAI2I3oJIAttyRNBl56WL9lb0q9vUAnlTZWR k8E1MYBnEtzPdzcfflCwrTs00PLUC9DtZUxadVrw+BsMAdKurwZ1wsKql+6JpPTwQdIK 7HnbG4d3zdNv2bRdelrIA1126aqEYsVYfnTv+raWrKN1FKsFzqzzvAyYmRHTWvt8DLSu k2pWnp8FzvMuiVy6LCGz7MvUslH96vbaJaT71vqsGXGgPgfQ50cXSosKybKyH0Tam2Ie /hOOFjp10b1PiErieNiSI3gETQveqwmzHgVtsCexA1qau2kOkxbRFzgMe3BHpktEcU3I 71kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=H/DjhFczaFNK9nZ317XhMDN4HkjytZIw2G1X+5F/vl4=; b=c4Ar+KFdsUFoxkuTEc4F1Urp3HxoyA6AJv+sZKs0gruEN42mX4X/3BnDk5dSN9GLEQ q33lw/3iHzcKflDVCI1UoM7+OnwDKZhGnuOpT6jsek2YglSWY+KB9y16D96PSeD9YtBe A1Ne0RASbi/SFHq4eDZePu0M2Dd058vPS3svbzbJMig13oFHendtfN0Guja0RCkJJJTc TfkOTiNgaOF6ufL+GoEpnIGTAg02nKiq7Tu2t1orXkb/SO3/HqIXvjCRQg8/nYLy0MfY sNt5FlltJGJYdIajGzmm4hNuTlhEDi3VgYJ+D27W578Unx29UCz6yv04BrY+35MmAGNu w6Tg== X-Gm-Message-State: AKGB3mLd2gKT79SK8iUe5nGQKxzW2Gsk3pPIdLT3KBJr0JpGLMnjBNWJ sgMlE6QonlpJs6TCIPerqs36LpRQJWNpJW0WjGW8KJ1gyObRpPoWV7PCS+Ue1TT5fyXzXUfD9hQ LbRuM440rEGqOZDNIr7tuAOVc+5x2TzjHM38Bbn0mj8iIHTuh5w55lPLfpSrg/KmbmnLnJ7nRO7 vv8K7vPCWvwg== X-Google-Smtp-Source: ACJfBotXhpUsOxxlq5aCRWRhNRygc4S4DKAxlTw32PJfvG7XEltyWnXz48XD8QXYpWB9mbSkLdUk5w== X-Received: by 10.223.128.67 with SMTP id 61mr18608363wrk.234.1515594508925; Wed, 10 Jan 2018 06:28:28 -0800 (PST) Received: from [192.168.0.3] (ath91-3-88-167-161-184.fbx.proxad.net. [88.167.161.184]) by smtp.gmail.com with ESMTPSA id z81sm729395wmc.32.2018.01.10.06.28.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2018 06:28:28 -0800 (PST) Subject: Re: [HACKERS] PATCH: psql tab completion for SELECT To: Edmund Horner Cc: pgsql-hackers@postgresql.org References: <034f9a0a-d426-251a-5f81-6083d730ee9e@2ndquadrant.com> From: Vik Fearing Organization: 2ndQuadrant France Message-ID: <2f1079b8-4c0d-b89e-e1d2-ab83e7dff978@2ndquadrant.com> Date: Wed, 10 Jan 2018 15:28:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/10/2018 06:38 AM, Edmund Horner wrote: > Hi Vik, thanks so much for the comments and the offer to review! > > I kept a low profile after my first message as there was already a > commitfest in progress, but now I'm working on a V2 patch. > > I will include aggregate and window functions as you suggest. And > I'll exclude trigger functions. Thanks. > I'd like to exclude more if we could, because there are already over > 1000 completions on an empty database. I had thought of filtering out > functions with an argument of type internal but couldn't figure out > how to interrogate the proargtypes oidvector in a nice way. If you just want to do internal, WHERE regtype 'internal' <> ALL (proargtypes) but if you'll want to add more banned types, then WHERE NOT (proargtypes::regtype[] && array['internal', 'unknown']::regtype[]) This is a very good test to add. > Regarding support for older versions, psql fails silently if a tab > completion query fails. No it doesn't, see below. > We could just let it do this, which is what > happens with, for example, ALTER PUBLICATION against a 9.6 server. I > can't see any existing completions that check the server version -- > but completions that don't work against older versions, like ALTER > PUBLICATION, also aren't useful for older versions. SELECT is a bit > different as it can be useful against older versions that don't have > the pg_aggregate.aggcombinefn that my query uses for filtering out > aggregation support functions. That's a bug in my opinion, but not one that needs to be addressed by this patch. There are no completions that cater to the server version (yet) but all the \d stuff certainly does. You can see that in action in src/bin/psql/describe.c as well as all over the place in pg_dump and the like. > There's also the small irritation that when a completion query fails, > it aborts the user's current transaction to provide an incentive for > handling older versions gracefully. That is actively hostile and not at all what I would consider "silently failing". If you don't want to do the multiple versions thing, you should at least check if you're on 9.6+ before issuing the query. > Regarding multiple columns, I have an idea that if we check that: > > a) the last of any SELECT/WHERE/GROUP BY/etc.-level keyword is a > SELECT (i.e. that we're in the SELECT clause of the query), and > b) the last word was a comma (or ended in a comma). > we can then proffer the column/function completions. > > There may be other completions that could benefit from such a check, > e.g. table names after a comma in the FROM clause, but I just want to > get SELECT working first. I would like to see this as a separate patch. Let's keep this one simple and just do like the other things currently do. -- Vik Fearing +33 6 46 75 15 36 http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support