mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
Add Send A Command To psql as a postgres til.
This commit is contained in:
@@ -65,6 +65,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
- [Intervals Of Time By Week](postgres/intervals-of-time-by-week.md)
|
||||
- [Limit Execution Time Of Statements](postgres/limit-execution-time-of-statements.md)
|
||||
- [List All Columns Of A Specific Type](postgres/list-all-columns-of-a-specific-type.md)
|
||||
- [Send A Command To psql](postgres/send-a-command-to-psql.md)
|
||||
- [String Contains Another String](postgres/string-contains-another-string.md)
|
||||
- [Temporarily Disable Triggers](postgres/temporarily-disable-triggers.md)
|
||||
- [Temporary Tables](postgres/temporary-tables.md)
|
||||
|
||||
23
postgres/send-a-command-to-psql.md
Normal file
23
postgres/send-a-command-to-psql.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user