File tree 2 files changed +49
-1
lines changed 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
7
7
warrant a full blog post. These are mostly things I learn by pairing with
8
8
smart people at [ Hashrocket] ( http://hashrocket.com/ ) .
9
9
10
- _ 397 TILs and counting..._
10
+ _ 398 TILs and counting..._
11
11
12
12
---
13
13
@@ -211,6 +211,7 @@ _397 TILs and counting..._
211
211
- [ Max Identifier Length Is 63 Bytes] ( postgres/max-identifier-length-is-63-bytes.md )
212
212
- [ pg Prefix Is Reserved For System Schemas] ( postgres/pg-prefix-is-reserved-for-system-schemas.md )
213
213
- [ Pretty Print Data Sizes] ( postgres/pretty-print-data-sizes.md )
214
+ - [ Print The Query Buffer In psql] ( postgres/print-the-query-buffer-in-psql.md )
214
215
- [ Renaming A Sequence] ( postgres/renaming-a-sequence.md )
215
216
- [ Renaming A Table] ( postgres/renaming-a-table.md )
216
217
- [ Restart A Sequence] ( postgres/restart-a-sequence.md )
Original file line number Diff line number Diff line change
1
+ # Print The Query Buffer In psql
2
+
3
+ I'll often be composing a PostgreSQL query in Vim and decide I want to give
4
+ it a try in ` psql ` . I copy the relevant snippet of SQL to my system buffer
5
+ and then paste into ` psql ` . I'm usually hit with a mess of text like this
6
+ though:
7
+
8
+ ``` sql
9
+ jbranchaud= # create table nullable_fields (
10
+ jbranchaud(# id serial primary key,
11
+ first varchar ,
12
+ last varchar
13
+ )
14
+ id serial primary key ,
15
+ jbranchaud(# first varchar,
16
+ last varchar
17
+ )
18
+ first varchar ,
19
+ jbranchaud(# last varchar
20
+ )
21
+ last varchar
22
+ jbranchaud(# )
23
+ )
24
+ jbranchaud- #
25
+ ```
26
+
27
+ Yikes. That's not readable. Fortunately, ` psql ` provides a command for
28
+ printing the current contents of the query buffer. By typing ` \p ` I'll see a
29
+ more readable version of what I just pasted in.
30
+
31
+ ``` sql
32
+ jbranchaud- # \p
33
+ create table nullable_fields (
34
+ id serial primary key ,
35
+ first varchar ,
36
+ last varchar
37
+ )
38
+ jbranchaud- #
39
+ ```
40
+
41
+ After taking another glance at the snippet of SQL, I decide to complete the
42
+ query to create my new table.
43
+
44
+ ``` sql
45
+ jbranchaud- # ;
46
+ CREATE TABLE
47
+ ```
You can’t perform that action at this time.
0 commit comments