Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eYw6A-0007Ua-3A for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jan 2018 15:45:58 +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 1eYw69-0000SS-Bc for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Jan 2018 15:45:57 +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 1eYw69-0000SI-0C for pgsql-hackers@lists.postgresql.org; Tue, 09 Jan 2018 15:45:57 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eYw5x-00056K-BX for pgsql-hackers@postgresql.org; Tue, 09 Jan 2018 15:45:56 +0000 Received: by mail-wm0-x243.google.com with SMTP id r78so21331826wme.5 for ; Tue, 09 Jan 2018 07:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:organization:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=dp0TBwYinFks6FB7l8vRIcRI8WFfSqivUMzSKe9+0vk=; b=cQDiC+35nMs6ac+WKMaB1YVfQP7RcWbitBWkFjFHrQIvFOsDfkSuUnBMrjW6W+zWIi 411Y6xe6gJMMFNfu3tSEHx7dglqedQ4E/eje/w/87sykPnz2oz9cy2c6WkUsAg0djWDJ EBRumxmOBMf5vg7lqzU8zqFq5Syc0KYHSfXWebhY9cfjZ1q+/H4Y3IzKuthFsrFr5R73 E0sA5vbNiNqx1+D2xKQvNoXYpZhgZlCJ6m9Wv09ZD2+x2FsDs3vrcVxulRSu6mcFSodg mcJ9U+kGx/nVNC8lc3zW1DN93QcLBY9YWRoSqib9+WacAdF+UAptY6hsmHsbDuVDPqA2 Hu+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=dp0TBwYinFks6FB7l8vRIcRI8WFfSqivUMzSKe9+0vk=; b=Fqz+KfYxh9kdjlL/503MwIRFCYXrrPhDNXxEiEIn9uLnDJXpasC2/20/UITcf+sx8y IA0SzIcXB7WJb43DGD+q1NF1ceIj1ln47AAXrtWPsCXUfBq5Ct9lTHdc8g96iOFw5Jvx 6HHLdy5pYD91vBo2YliAL1sOXnG6sK0K9mrd0PyCRSKf66jcWVD7FHi9OIS/T7g/tmi4 ZVtow9/OhcPM4v+3yIdNEi9fa8zIWxCXtT1Zu4q9UpSPWPJu+XEwyVckxrmqpDM25NE/ /biMYLH1ZE0Se94GIvUx0J4mDcQpwh3X6/XpDYFgfZ7p+/NL2dOyhqF4xCES5EDT1uXr TxSw== X-Gm-Message-State: AKGB3mJnhBcIL+ketUdD62k2Y9xLhyRLZNDBUMhKvrMObNxTsLICU5pR cT9VFVXgb2CPE9hUtRY97+0EuOs4T+YqSLbW3flG5lN6/eFPKRzyD3wC5bs++VKhMTrp9rKkS24 yx9lciGfQKhf4Xw5eL5gRuAs0hC4p935UQ7LCxMX9KhVnAPwllMHTBuH1QSZqWZUqYdzio7gNK1 KuX3/G1xmxzg== X-Google-Smtp-Source: ACJfBosz+I9x6tk8dWHay2LvUQT9M6QhCwlymkNRTJXbDub0iyYHfnxT5IyT0GlIGCI5IMDjR6aotg== X-Received: by 10.28.192.13 with SMTP id q13mr12043454wmf.20.1515512743432; Tue, 09 Jan 2018 07:45:43 -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 g78sm19501055wmc.30.2018.01.09.07.45.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 07:45:42 -0800 (PST) Subject: Re: [HACKERS] PATCH: psql tab completion for SELECT To: Edmund Horner , pgsql-hackers@postgresql.org References: From: Vik Fearing Organization: 2ndQuadrant France Message-ID: <034f9a0a-d426-251a-5f81-6083d730ee9e@2ndquadrant.com> Date: Tue, 9 Jan 2018 16:45:41 +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 11/06/2017 05:28 AM, Edmund Horner wrote: > Hi pgsql-hackers, > > Here's a little draft patch to add *some* tab completion ability for > SELECT in psql. I have often missed the ability, especially with > invocations of utility functions. Yes, indeed! The vast majority of what I use interactive psql for is to call functions. The fact that it does columns as well is nice, and not doing anything after the first isn't a problem as we have many other places where that's the case. It's annoying, but consistent with current annoying behavior. So no points off for that. > What my patch does: > > For a command line with the single word SELECT, column names and > function names will be used for completions of the next word. > Function names have a "(" suffix added, largely because it makes them > easier to distinguish in the completion list. And because the user is going to have to type one anyway. The completion mechanism adds a space after the paren, which is a needle in the eye of my OCD, but that's not this patch's fault. > Only the first select-list item can be tab-completed; i.e. SELECT foo, > b won't find column bar. That's not a problem for me. > How it works: > > The implementation uses a normal non-schema query, because columns > don't have schemas. > > The eligible columns are normal, visible columns. At first I thought this was too broad, but of course it's not because the column will be visible if the user schema-qualifies the table it's in. > I have tried to filter out the various functions which aren't likely > to be directly used in queries. > > The eligible functions are those which are: > - visible Yes. > - not aggregate or window functions Why? I think this is a big mistake. > - not RI_FKey_* functions Agreed. > - not support functions for types, aggregates, operators, languages, > casts, access methods. That list looks good to me. But you forgot to exclude trigger functions. > Is this likely to be a useful addition to PostgreSQL? Yes, very much so. > Some other questions about how it should be done: > > - Are my criteria for the columns and function names appropriate? No, I don't think so, as mentioned above. > - Should I try to use a SchemaQuery so that function schema names can be used? > > - Should I try to support simple cases of multiple columns? (How? > We can use TailMatches1(",") but how do we tell we aren't into the > FROM-clause or later?) I think these two can be pushed to a later patch. I'd rather have what you've got now than nothing at all. > - How do we make it work with older servers, e.g. those that predate > some of the newer columns used in the function criteria? This is something that's going to have to be addressed if this patch is to be committed. The way to do this is by writing a query for each different version you need to support and then call the right one depending on the pset.sversion global variable. Marking as Waiting on Author. -- Vik Fearing +33 6 46 75 15 36 http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support