kdb: What is the meaning of this command line prompt q.Q) - kdb

The normal prompt is q), what is the meaning of q.Q)?
I think I got stuck in this after pressing Ctrl-C while a query is running.

It means you've interrupted execution inside one of the .Q functions, see https://code.kx.com/q/ref/#q
You can usually return to the normal prompt by changing namespace back to the default namespace
\d .

Related

Why does the debugger in KDB sometimes not show in 'interactive' mode?

I've got a function where I'm throwing a deliberate error to pause execution and enter interactive debug.
I have set \e 1.
When the KDB REPL encounters it, it pauses execution as expected, but the debugger doesn't actually appear. When I finally enter \, it prints the debugger output, like it was printing to an invisible terminal, but then drops to the normal namespace.
What am I doing wrong?
Video of the problem:
https://www.loom.com/share/db9ee83e7d8e4fb7bb6b454b49ec9cdc

Incorrect PSQL command puts sql in a state that cannot be exited unless exiting from PSQL completely

As you can see I did not quote Hill correctly thus making the SQL command incorrect. The first SQL line has the database name followed by =# the second line has -#. After the incorrect SQL command there is '#.
The issue is no matter what, I cannot exit the '#.
Only option is to quit psql with \q. Is there a way to go back from '# to =# instead of completely exiting psql?
The '# tells you there is a dangling quote.
To finish the statement enter '); on the '# prompt.
The ' closes the string. The ) ends the VALUES part of the INSERT and the ; ends the whole statement resulting in a syntax error (obviously)
In my hands, you can't even use \q to quit, as that can be a legitimate part of a single-quote quoted string. I just get a message (on Linux) saying Use control-D to quit., which does work.
But to get out of the line entry without closing psql, another thing that you can do is hitting ctrl-C. (But this doesn't work on MSWindows, it bombs all the way out of psql). The problem with that is that you lose your buffer.
If you want to preserve your query buffer so you can go back and edit it to fix the problem, then do as the horse suggests and just close the quote and whatever other open constructs you have, to get the syntax error. Then hit the up arrow to go edit it, adding the missing quote in the proper place and deleting the extra one you had to add at the end to get things to close out. To be really careful, you should make sure the thing you are about to submit really is going to be a syntax error, and not accidentally a valid statement which does something you don't want. When attached to production, I take the ctrl-C route and accept the loss of the query buffer, it is safer.

Postgres Command line - clear/delete a query that I was in the middle of typing

Is there a way to quickly delete an entire query that I've been typing?
To clarify, this would be a query I'm still typing, not something that's currently running.
For example in bash, you can hit CTRL+C and it kills your current line, like:
$ typing some comman<CTRL-C>
After pressing CTRL+C it stops the previous stuff I have typed without executing.
It's just a thing I'm used to doing for quickly switching trains of thought ("oh what if I do this instead of this?"), but CTRL+C in the postgres terminal just terminates the process.
Aa alternative to Ctrl+C is Ctrl+ACtrl+K. While Ctrl+A moves the cursor to the beginning of the current line, Ctrl+K deletes all characters after the cursor.
This can be used in bash or many other UNIX commands, too.

How to get out of a select in PostgreSQL without exiting to the terminal?

As you see in the image I have listed all the tables in a database...
I can move up and down, but how can I get back to the postgres prompt? If I use CONTROL+X it takes me back to the linux prompt, but out of postgres.
Thank you ALL for your patience with non-programmers!
It's less pager, simply type q.
https://www.postgresql.org/docs/current/static/app-psql.html
If the environment variable PAGER is set, the output is piped to the
specified program. Otherwise a platform-dependent default (such as
more) is used
so If you are on linux and did not explicitely change PAGER, tap q
http://man7.org/linux/man-pages/man1/more.1.html
Press space to continue, 'q' to quit.

Matlab-like command history retrieval in unix command line

In Matlab, there is a very nice feature that I like. Suppose I typed the command very-long-command and then a few several commands afterwards. Then later if I need the long command again, I just type very and press the up arrow key, my long command appears. It finds the last command that starts with very. I couldn't do the same in unix command line, when I try to do it, it disregards whatever I typed, and goes back to the last commands in chronological order. Is there a way to do it?
In bash this functionality is provided by the commands history-search-forward and history-search-backward, which by default are not bound to any keys (see here). If you run
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
it will make up-arrow and down-arrow search backward and forward through the history for the string of characters between the start of the current line and the point. See also this related Stack Overflow question.
In bash, hitting ctrl-r will let you do a history search:
$ echo 'something very long'
something very long
$ # blah
$ # many commands later...
(reverse-i-search)`ec': echo 'something very long'
In the above snippet, I hit ctrl-r on the next line after # many commands later..., and then typed ec which brought me back to the echo command. At that point hitting Enter will execute the command.
You can do the same thing by using "!". For example:
$ echo "Hello"
Hello
$ !echo
echo "Hello"
Hello
However, it is generally a bad idea to do this sort of thing (what if the last command did something destructive?). If you expect you will reuse something, then I suggest you create a shell script and save it away somewhere (whenever I plan to reuse something, I create a script in ~/.local/bin).