mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Print The Query Buffer In psql as a postgres til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
||||
warrant a full blog post. These are mostly things I learn by pairing with
|
||||
smart people at [Hashrocket](http://hashrocket.com/).
|
||||
|
||||
_397 TILs and counting..._
|
||||
_398 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -211,6 +211,7 @@ _397 TILs and counting..._
|
||||
- [Max Identifier Length Is 63 Bytes](postgres/max-identifier-length-is-63-bytes.md)
|
||||
- [pg Prefix Is Reserved For System Schemas](postgres/pg-prefix-is-reserved-for-system-schemas.md)
|
||||
- [Pretty Print Data Sizes](postgres/pretty-print-data-sizes.md)
|
||||
- [Print The Query Buffer In psql](postgres/print-the-query-buffer-in-psql.md)
|
||||
- [Renaming A Sequence](postgres/renaming-a-sequence.md)
|
||||
- [Renaming A Table](postgres/renaming-a-table.md)
|
||||
- [Restart A Sequence](postgres/restart-a-sequence.md)
|
||||
|
||||
47
postgres/print-the-query-buffer-in-psql.md
Normal file
47
postgres/print-the-query-buffer-in-psql.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Print The Query Buffer In psql
|
||||
|
||||
I'll often be composing a PostgreSQL query in Vim and decide I want to give
|
||||
it a try in `psql`. I copy the relevant snippet of SQL to my system buffer
|
||||
and then paste into `psql`. I'm usually hit with a mess of text like this
|
||||
though:
|
||||
|
||||
```sql
|
||||
jbranchaud=# create table nullable_fields (
|
||||
jbranchaud(# id serial primary key,
|
||||
first varchar,
|
||||
last varchar
|
||||
)
|
||||
id serial primary key,
|
||||
jbranchaud(# first varchar,
|
||||
last varchar
|
||||
)
|
||||
first varchar,
|
||||
jbranchaud(# last varchar
|
||||
)
|
||||
last varchar
|
||||
jbranchaud(# )
|
||||
)
|
||||
jbranchaud-#
|
||||
```
|
||||
|
||||
Yikes. That's not readable. Fortunately, `psql` provides a command for
|
||||
printing the current contents of the query buffer. By typing `\p` I'll see a
|
||||
more readable version of what I just pasted in.
|
||||
|
||||
```sql
|
||||
jbranchaud-# \p
|
||||
create table nullable_fields (
|
||||
id serial primary key,
|
||||
first varchar,
|
||||
last varchar
|
||||
)
|
||||
jbranchaud-#
|
||||
```
|
||||
|
||||
After taking another glance at the snippet of SQL, I decide to complete the
|
||||
query to create my new table.
|
||||
|
||||
```sql
|
||||
jbranchaud-# ;
|
||||
CREATE TABLE
|
||||
```
|
||||
Reference in New Issue
Block a user