Installing duckDB
Installation
DuckDB has been installed on the MEDS server. We also recommend to install it on your personal machine following those instructions: https://duckdb.org/docs/installation/
Visual code integration (optional)
You can use DuckDB directly from the terminal but if you also want to have the option to have both a SQL script and the terminal open, we recommend to use visual code. There is one setting to be done to link the script and the terminal:
In Visual Code:
open the palette Shift+Cmd+P and search for:
Preferences: Open Keyboard Shortcuts (JSON)
enter the following text & save
// Place your key bindings in this file to override the defaults
[
{
"key": "shift+enter",
"command": "workbench.action.terminal.runSelectedText"
}
]
OR alternative method to set this up:
Under the main VS menu, go to Settings -> Keyboard Shortcuts, search for “run selected”, the “run selected text in active terminal” will be one of the options. Set the shift-enter keypress by double-clicking. Right-click on the When column, select Change When Expression, and add editorLangId == 'sql'
to restrict to just SQL files and not every kind of file.
Now you can hit Shift+Return at then end of a line in your SQL script and it should run the command directly in the terminal!
Test
Let’s test our new installation using visual code
open a terminal from the terminal menu -> new terminal
In the terminal type
duckdb
, this should start duckdbOpen a New text file: file menu -> new text file
Copy paste the following code:
-- Start the DB at the terminal: duckdb
CREATE TABLE ducks AS SELECT 3 As age, 'mandarin' AS breed;
TABLES;
SHOW
FROM ducks SELECT *;
- Use Shift+Return to run the SQL code line by line
You should have something that looks like this: