Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I cancel a bad command in Postgres (from terminal)?

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.

like image 670
LoveMeow Avatar asked Sep 17 '15 14:09

LoveMeow


1 Answers

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

like image 64
Douglas Lee Avatar answered Oct 21 '22 17:10

Douglas Lee