mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
24 lines
355 B
Markdown
24 lines
355 B
Markdown
# Send A Command To psql
|
|
|
|
You can send a command to `psql` to be executed by using the `-c` flag
|
|
|
|
```bash
|
|
$ psql -c "select 'Hello, World!';"
|
|
?column?
|
|
---------------
|
|
Hello, World!
|
|
(1 row)
|
|
```
|
|
|
|
Specify a particular database as needed
|
|
|
|
```bash
|
|
$ psql blog_prod -c 'select count(*) from posts;'
|
|
count
|
|
-------
|
|
8
|
|
(1 row)
|
|
```
|
|
|
|
h/t Jack Christensen
|