Thread: Annoying messages when copy sql code to psql terminal

Annoying messages when copy sql code to psql terminal

From
"A B"
Date:
Whenever I use copy-paste to run code in a terminal window that is
running psql, and the code contains a row like

IF FOUND THEN

then I get the words

ABORT        CHECKPOINT   COMMIT       DECLARE      EXECUTE
INSERT       MOVE         REINDEX      ROLLBACK     SHOW
UPDATE
ALTER        CLOSE        COPY         DELETE FROM  EXPLAIN
LISTEN       NOTIFY       RELEASE      SAVEPOINT    START
VACUUM
ANALYZE      CLUSTER      CREATE       DROP         FETCH        LOAD
       PREPARE      RESET        SELECT       TRUNCATE
BEGIN        COMMENT      DEALLOCATE   END          GRANT        LOCK
       REASSIGN     REVOKE       SET          UNLISTEN

That must be some kind of display of possible stuff to write after
"THEN" but it is very annoying. How to turn it of?

Re: Annoying messages when copy sql code to psql terminal

From
Sam Mason
Date:
On Tue, May 27, 2008 at 03:24:38PM +0200, A B wrote:
> Whenever I use copy-paste to run code in a terminal window that is
> running psql, and the code contains a row like
>
> IF FOUND THEN
>
> then I get the words

 [...]

> That must be some kind of display of possible stuff to write after
> "THEN" but it is very annoying. How to turn it of?

I'd guess the next line of code starts with a tab character and hence
psql is just tab completing the (empty) line.  If you don't want this to
happen, you can disable table completion.  From the man page:

       If
       for some reason you do not like the tab completion, you can turn it off
       by putting this in a file named .inputrc in your home directory:

       $if psql
       set disable-completion on
       $endif

As an aside, there isn't an "if" statement in SQL.


  Sam

Re: Annoying messages when copy sql code to psql terminal

From
Tom Lane
Date:
"A B" <gentosaker@gmail.com> writes:
> Whenever I use copy-paste to run code in a terminal window that is
> running psql, and the code contains a row like

> IF FOUND THEN

> then I get the words

> ABORT        CHECKPOINT   COMMIT       DECLARE      EXECUTE
> ...

Either avoid copying/pasting tabs, or turn off readline
(-n option to psql, I think, but check the manual).

There's probably a way to turn off tab-completion without
disabling readline altogether, but I don't know how offhand.

            regards, tom lane

Re: Annoying messages when copy sql code to psql terminal

From
Alvaro Herrera
Date:
Tom Lane escribió:
> "A B" <gentosaker@gmail.com> writes:
> > Whenever I use copy-paste to run code in a terminal window that is
> > running psql, and the code contains a row like
> > [...]

> Either avoid copying/pasting tabs, or turn off readline
> (-n option to psql, I think, but check the manual).
>
> There's probably a way to turn off tab-completion without
> disabling readline altogether, but I don't know how offhand.

This can be done by adding

$if psql
   set disable-completion on
$endif

to .inputrc.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: Annoying messages when copy sql code to psql terminal

From
"Merlin Moncure"
Date:
On Tue, May 27, 2008 at 9:24 AM, A B <gentosaker@gmail.com> wrote:
> Whenever I use copy-paste to run code in a terminal window that is
> running psql, and the code contains a row like
>
> IF FOUND THEN
>
> then I get the words
>
> ABORT        CHECKPOINT   COMMIT       DECLARE      EXECUTE

[...]

As others have noted, you have tabs in your sql source.  I'd advise if
possible, not to use the tab character in sql, for this and other
reasons.

merlin

Re: Annoying messages when copy sql code to psql terminal

From
"Gurjeet Singh"
Date:
On Fri, Jun 6, 2008 at 7:58 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
On Tue, May 27, 2008 at 9:24 AM, A B <gentosaker@gmail.com> wrote:
> Whenever I use copy-paste to run code in a terminal window that is
> running psql, and the code contains a row like
>
> IF FOUND THEN
>
> then I get the words
>
> ABORT        CHECKPOINT   COMMIT       DECLARE      EXECUTE

[...]

As others have noted, you have tabs in your sql source.  I'd advise if
possible, not to use the tab character in sql, for this and other
reasons.

Can you please elaborate on other reasons? I have never encountered any _other_ reason!!

And 'using psql' is not reason enough to not indent your SQL code.

Best regards,
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com

EnterpriseDB http://www.enterprisedb.com

Mail sent from my BlackLaptop device

Re: Annoying messages when copy sql code to psql terminal

From
"Merlin Moncure"
Date:
On Fri, Jun 6, 2008 at 12:39 AM, Gurjeet Singh <singh.gurjeet@gmail.com> wrote:
> On Fri, Jun 6, 2008 at 7:58 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
>> As others have noted, you have tabs in your sql source.  I'd advise if
>> possible, not to use the tab character in sql, for this and other
>> reasons.
>
> Can you please elaborate on other reasons? I have never encountered any
> _other_ reason!!
>
> And 'using psql' is not reason enough to not indent your SQL code.

For example, another reason tabs are annoying are how your function
sources show up in '\df+' (escaped).  iirc you can get around this
with '\x', but why bother with that?  Also, I am not suggesting not to
indent your sql, just not to use the tab character.

merlin

Re: Annoying messages when copy sql code to psql terminal

From
"Scott Marlowe"
Date:
On Fri, Jun 6, 2008 at 6:12 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
> On Fri, Jun 6, 2008 at 12:39 AM, Gurjeet Singh <singh.gurjeet@gmail.com> wrote:
>> On Fri, Jun 6, 2008 at 7:58 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
>>> As others have noted, you have tabs in your sql source.  I'd advise if
>>> possible, not to use the tab character in sql, for this and other
>>> reasons.
>>
>> Can you please elaborate on other reasons? I have never encountered any
>> _other_ reason!!
>>
>> And 'using psql' is not reason enough to not indent your SQL code.
>
> For example, another reason tabs are annoying are how your function
> sources show up in '\df+' (escaped).  iirc you can get around this
> with '\x', but why bother with that?  Also, I am not suggesting not to
> indent your sql, just not to use the tab character.

Almost every decent text editor has the option to use spaces in place
of tabs.  Even Nano can do it.

Re: Annoying messages when copy sql code to psql terminal

From
Reece Hart
Date:
On Thu, 2008-06-05 at 22:28 -0400, Merlin Moncure wrote:
As others have noted, you have tabs in your sql source.  I'd advise if
possible, not to use the tab character in sql, for this and other
reasons.

Tabs in SQL are a problem only if you copy-paste. If your editor and psql can see the same files (i.e., are running on the same machine or you're saving to a network fs), it's more reliable to save the file and read it in psql with \i or with psql -f. (\i and -f won't try to do tab completion, of course.)

-Reece

-- 
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0