12

I wrote a bad command( I made a mistake in the function and want to exit it without completing the function) while trying to write a function, and I want to exit it,but the command prompt of Terminal wont let me.

I tried this : https://unix.stackexchange.com/questions/45646/how-do-i-exit-or-cancel-a-bad-bash-command

also this

stackoverflow.com/questions/12649896/why-doesnt-my-terminal-output-unicode-characters-properly

But none of the solutions given work, I am in this situation now (I was trying to write a pgplsql function and I wanted to end it, but I don't know how)

message=# create function add_message(_queue_id integer, _sender_id integer, _receiver_id integer, _payload text)
message-# returns integer as $$
message$# declare
message$# result integer;
message$# begin
message$# ;
message$# ;
message$# ;
message$# ;
message$# sdsd
message$# end
message$# ;
message$# return result;
message$# end
message$# <aa
message$# -ls
message$# ls
message$# abort
message$# v
message$#

I tried :

ctrl + /
crtl+D
ctrl+Z
ctrl+C
esc key
exit 0
:q

Note: I am using a osx keyboard with swiss-german layout.

Community
  • 1
  • 1
LoveMeow
  • 3,858
  • 9
  • 44
  • 66

2 Answers2

15

I realize this is an old post, but this was my question too and took some time to eventually find the answer. By terminal, I believe op meant psql command line.

\r or \reset was what I was looking for. Resets (clears) the query buffer.

https://www.postgresql.org/docs/9.2/app-psql.html

Watercayman
  • 7,970
  • 10
  • 31
  • 49
Douglas Lee
  • 151
  • 1
  • 6
0

From postgresql try \q. See exit for more. Or, for more drastic cases: From another terminal window do

ps

it will give a list like

  PID TTY           TIME CMD
57839 ttys000    0:00.02 -bash
57838 ttys001    0:00.05 -bash
57840 ttys002    0:00.17 -bash

divine which is the offending process and kill it

kill 57839

A new terminal should come up with a later number. See Processes and Daemons for more.

Community
  • 1
  • 1
Robert E
  • 413
  • 4
  • 7
  • 2
    if i do \q wont it exit psql totally? – LoveMeow Sep 17 '15 at 14:43
  • @LoveMeow Are you being serious? – trojanfoe Sep 17 '15 at 14:44
  • @robert is there something else like ctrl-d that just exits the current command? – LoveMeow Sep 17 '15 at 15:13
  • Programs can take control of all characters so it really depends on what postgresql does. So you can learn more about postgresql or just start over (the kill or even a reboot will do this.) It all depends on where you want to devote your learning curve. You could also just try typing a bunch of ')' and '}' to see if that will finish what you started to enter. – Robert E Sep 17 '15 at 20:20