Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
c64e68fd
Commit
c64e68fd
authored
Oct 03, 2013
by
Robert Haas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
psql: Make \pset without arguments show all settings.
Gilles Darold, reviewed by Pavel Stehule
parent
c2b175b9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
196 additions
and
93 deletions
+196
-93
doc/src/sgml/ref/psql-ref.sgml
doc/src/sgml/ref/psql-ref.sgml
+1
-4
src/bin/psql/command.c
src/bin/psql/command.c
+175
-88
src/bin/psql/help.c
src/bin/psql/help.c
+1
-1
src/test/regress/expected/psql.out
src/test/regress/expected/psql.out
+16
-0
src/test/regress/sql/psql.sql
src/test/regress/sql/psql.sql
+3
-0
No files found.
doc/src/sgml/ref/psql-ref.sgml
View file @
c64e68fd
...
...
@@ -2272,13 +2272,10 @@ lo_import 152801
</para>
</tip>
<note>
<para>
It is an error to call <command>\pset</command> without any
arguments. In the future this case might show the current status
<command>\pset</command> without any arguments displays the current status
of all printing options.
</para>
</note>
</listitem>
</varlistentry>
...
...
src/bin/psql/command.c
View file @
c64e68fd
...
...
@@ -68,6 +68,7 @@ static int strip_lineno_from_funcdesc(char *func);
static
void
minimal_error_message
(
PGresult
*
res
);
static
void
printSSLInfo
(
void
);
static
bool
printPsetInfo
(
const
char
*
param
,
struct
printQueryOpt
*
popt
);
#ifdef WIN32
static
void
checkWin32Codepage
(
void
);
...
...
@@ -1045,8 +1046,20 @@ exec_command(const char *cmd,
if
(
!
opt0
)
{
psql_error
(
"
\\
%s: missing required argument
\n
"
,
cmd
);
success
=
false
;
size_t
i
;
/* list all variables */
static
const
char
*
const
my_list
[]
=
{
"border"
,
"columns"
,
"expanded"
,
"fieldsep"
,
"footer"
,
"format"
,
"linestyle"
,
"null"
,
"numericlocale"
,
"pager"
,
"recordsep"
,
"tableattr"
,
"title"
,
"tuples_only"
,
NULL
};
for
(
i
=
0
;
my_list
[
i
]
!=
NULL
;
i
++
)
{
printPsetInfo
(
my_list
[
i
],
&
pset
.
popt
);
}
success
=
true
;
}
else
success
=
do_pset
(
opt0
,
opt1
,
&
pset
.
popt
,
pset
.
quiet
);
...
...
@@ -2275,8 +2288,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
return
false
;
}
if
(
!
quiet
)
printf
(
_
(
"Output format is %s.
\n
"
),
_align2string
(
popt
->
topt
.
format
));
}
/* set table line style */
...
...
@@ -2296,9 +2307,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
return
false
;
}
if
(
!
quiet
)
printf
(
_
(
"Line style is %s.
\n
"
),
get_line_style
(
&
popt
->
topt
)
->
name
);
}
/* set border style/width */
...
...
@@ -2307,8 +2315,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
if
(
value
)
popt
->
topt
.
border
=
atoi
(
value
);
if
(
!
quiet
)
printf
(
_
(
"Border style is %d.
\n
"
),
popt
->
topt
.
border
);
}
/* set expanded/vertical mode */
...
...
@@ -2320,15 +2326,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
expanded
=
ParseVariableBool
(
value
);
else
popt
->
topt
.
expanded
=
!
popt
->
topt
.
expanded
;
if
(
!
quiet
)
{
if
(
popt
->
topt
.
expanded
==
1
)
printf
(
_
(
"Expanded display is on.
\n
"
));
else
if
(
popt
->
topt
.
expanded
==
2
)
printf
(
_
(
"Expanded display is used automatically.
\n
"
));
else
printf
(
_
(
"Expanded display is off.
\n
"
));
}
}
/* locale-aware numeric output */
...
...
@@ -2338,13 +2335,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
numericLocale
=
ParseVariableBool
(
value
);
else
popt
->
topt
.
numericLocale
=
!
popt
->
topt
.
numericLocale
;
if
(
!
quiet
)
{
if
(
popt
->
topt
.
numericLocale
)
puts
(
_
(
"Showing locale-adjusted numeric output."
));
else
puts
(
_
(
"Locale-adjusted numeric output is off."
));
}
}
/* null display */
...
...
@@ -2355,8 +2345,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
free
(
popt
->
nullPrint
);
popt
->
nullPrint
=
pg_strdup
(
value
);
}
if
(
!
quiet
)
printf
(
_
(
"Null display is
\"
%s
\"
.
\n
"
),
popt
->
nullPrint
?
popt
->
nullPrint
:
""
);
}
/* field separator for unaligned text */
...
...
@@ -2368,13 +2356,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
fieldSep
.
separator
=
pg_strdup
(
value
);
popt
->
topt
.
fieldSep
.
separator_zero
=
false
;
}
if
(
!
quiet
)
{
if
(
popt
->
topt
.
fieldSep
.
separator_zero
)
printf
(
_
(
"Field separator is zero byte.
\n
"
));
else
printf
(
_
(
"Field separator is
\"
%s
\"
.
\n
"
),
popt
->
topt
.
fieldSep
.
separator
);
}
}
else
if
(
strcmp
(
param
,
"fieldsep_zero"
)
==
0
)
...
...
@@ -2382,8 +2363,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
free
(
popt
->
topt
.
fieldSep
.
separator
);
popt
->
topt
.
fieldSep
.
separator
=
NULL
;
popt
->
topt
.
fieldSep
.
separator_zero
=
true
;
if
(
!
quiet
)
printf
(
_
(
"Field separator is zero byte.
\n
"
));
}
/* record separator for unaligned text */
...
...
@@ -2395,15 +2374,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
recordSep
.
separator
=
pg_strdup
(
value
);
popt
->
topt
.
recordSep
.
separator_zero
=
false
;
}
if
(
!
quiet
)
{
if
(
popt
->
topt
.
recordSep
.
separator_zero
)
printf
(
_
(
"Record separator is zero byte.
\n
"
));
else
if
(
strcmp
(
popt
->
topt
.
recordSep
.
separator
,
"
\n
"
)
==
0
)
printf
(
_
(
"Record separator is <newline>."
));
else
printf
(
_
(
"Record separator is
\"
%s
\"
.
\n
"
),
popt
->
topt
.
recordSep
.
separator
);
}
}
else
if
(
strcmp
(
param
,
"recordsep_zero"
)
==
0
)
...
...
@@ -2411,8 +2381,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
free
(
popt
->
topt
.
recordSep
.
separator
);
popt
->
topt
.
recordSep
.
separator
=
NULL
;
popt
->
topt
.
recordSep
.
separator_zero
=
true
;
if
(
!
quiet
)
printf
(
_
(
"Record separator is zero byte.
\n
"
));
}
/* toggle between full and tuples-only format */
...
...
@@ -2422,13 +2390,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
tuples_only
=
ParseVariableBool
(
value
);
else
popt
->
topt
.
tuples_only
=
!
popt
->
topt
.
tuples_only
;
if
(
!
quiet
)
{
if
(
popt
->
topt
.
tuples_only
)
puts
(
_
(
"Showing only tuples."
));
else
puts
(
_
(
"Tuples only is off."
));
}
}
/* set title override */
...
...
@@ -2439,14 +2400,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
title
=
NULL
;
else
popt
->
title
=
pg_strdup
(
value
);
if
(
!
quiet
)
{
if
(
popt
->
title
)
printf
(
_
(
"Title is
\"
%s
\"
.
\n
"
),
popt
->
title
);
else
printf
(
_
(
"Title is unset.
\n
"
));
}
}
/* set HTML table tag options */
...
...
@@ -2457,14 +2410,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
tableAttr
=
NULL
;
else
popt
->
topt
.
tableAttr
=
pg_strdup
(
value
);
if
(
!
quiet
)
{
if
(
popt
->
topt
.
tableAttr
)
printf
(
_
(
"Table attribute is
\"
%s
\"
.
\n
"
),
popt
->
topt
.
tableAttr
);
else
printf
(
_
(
"Table attributes unset.
\n
"
));
}
}
/* toggle use of pager */
...
...
@@ -2481,15 +2426,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
pager
=
0
;
else
popt
->
topt
.
pager
=
1
;
if
(
!
quiet
)
{
if
(
popt
->
topt
.
pager
==
1
)
puts
(
_
(
"Pager is used for long output."
));
else
if
(
popt
->
topt
.
pager
==
2
)
puts
(
_
(
"Pager is always used."
));
else
puts
(
_
(
"Pager usage is off."
));
}
}
/* disable "(x rows)" footer */
...
...
@@ -2499,13 +2435,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt
->
topt
.
default_footer
=
ParseVariableBool
(
value
);
else
popt
->
topt
.
default_footer
=
!
popt
->
topt
.
default_footer
;
if
(
!
quiet
)
{
if
(
popt
->
topt
.
default_footer
)
puts
(
_
(
"Default footer is on."
));
else
puts
(
_
(
"Default footer is off."
));
}
}
/* set border style/width */
...
...
@@ -2513,9 +2442,167 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
{
if
(
value
)
popt
->
topt
.
columns
=
atoi
(
value
);
}
else
{
psql_error
(
"
\\
pset: unknown option: %s
\n
"
,
param
);
return
false
;
}
if
(
!
quiet
)
printPsetInfo
(
param
,
&
pset
.
popt
);
return
true
;
}
static
bool
printPsetInfo
(
const
char
*
param
,
struct
printQueryOpt
*
popt
)
{
Assert
(
param
!=
NULL
);
/* show border style/width */
if
(
strcmp
(
param
,
"border"
)
==
0
)
{
if
(
!
popt
->
topt
.
border
)
printf
(
_
(
"Border style (%s) unset.
\n
"
),
param
);
else
printf
(
_
(
"Border style (%s) is %d.
\n
"
),
param
,
popt
->
topt
.
border
);
}
/* show the target width for the wrapped format */
else
if
(
strcmp
(
param
,
"columns"
)
==
0
)
{
if
(
!
popt
->
topt
.
columns
)
printf
(
_
(
"Target width (%s) unset.
\n
"
),
param
);
else
printf
(
_
(
"Target width (%s) is %d.
\n
"
),
param
,
popt
->
topt
.
columns
);
}
/* show expanded/vertical mode */
else
if
(
strcmp
(
param
,
"x"
)
==
0
||
strcmp
(
param
,
"expanded"
)
==
0
||
strcmp
(
param
,
"vertical"
)
==
0
)
{
if
(
popt
->
topt
.
expanded
==
1
)
printf
(
_
(
"Expanded display (%s) is on.
\n
"
),
param
);
else
if
(
popt
->
topt
.
expanded
==
2
)
printf
(
_
(
"Expanded display (%s) is used automatically.
\n
"
),
param
);
else
printf
(
_
(
"Expanded display (%s) is off.
\n
"
),
param
);
}
/* show field separator for unaligned text */
else
if
(
strcmp
(
param
,
"fieldsep"
)
==
0
)
{
if
(
popt
->
topt
.
fieldSep
.
separator_zero
)
printf
(
_
(
"Field separator (%s) is zero byte.
\n
"
),
param
);
else
printf
(
_
(
"Field separator (%s) is
\"
%s
\"
.
\n
"
),
param
,
popt
->
topt
.
fieldSep
.
separator
);
}
else
if
(
strcmp
(
param
,
"fieldsep_zero"
)
==
0
)
{
printf
(
_
(
"Field separator (%s) is zero byte.
\n
"
),
param
);
}
/* show disable "(x rows)" footer */
else
if
(
strcmp
(
param
,
"footer"
)
==
0
)
{
if
(
popt
->
topt
.
default_footer
)
printf
(
_
(
"Default footer (%s) is on.
\n
"
),
param
);
else
printf
(
_
(
"Default footer (%s) is off."
),
param
);
}
/* show format */
else
if
(
strcmp
(
param
,
"format"
)
==
0
)
{
if
(
!
popt
->
topt
.
format
)
printf
(
_
(
"Output format (%s) is aligned.
\n
"
),
param
);
else
printf
(
_
(
"Output format (%s) is %s.
\n
"
),
param
,
_align2string
(
popt
->
topt
.
format
));
}
/* show table line style */
else
if
(
strcmp
(
param
,
"linestyle"
)
==
0
)
{
printf
(
_
(
"Line style (%s) is %s.
\n
"
),
param
,
get_line_style
(
&
popt
->
topt
)
->
name
);
}
/* show null display */
else
if
(
strcmp
(
param
,
"null"
)
==
0
)
{
printf
(
_
(
"Null display (%s) is
\"
%s
\"
.
\n
"
),
param
,
popt
->
nullPrint
?
popt
->
nullPrint
:
""
);
}
/* show locale-aware numeric output */
else
if
(
strcmp
(
param
,
"numericlocale"
)
==
0
)
{
if
(
popt
->
topt
.
numericLocale
)
printf
(
_
(
"Locale-adjusted numeric output (%s) is on.
\n
"
),
param
);
else
printf
(
_
(
"Locale-adjusted numeric output (%s) is off.
\n
"
),
param
);
}
/* show toggle use of pager */
else
if
(
strcmp
(
param
,
"pager"
)
==
0
)
{
if
(
popt
->
topt
.
pager
==
1
)
printf
(
_
(
"Pager (%s) is used for long output.
\n
"
),
param
);
else
if
(
popt
->
topt
.
pager
==
2
)
printf
(
_
(
"Pager (%s) is always used.
\n
"
),
param
);
else
printf
(
_
(
"Pager (%s) usage is off.
\n
"
),
param
);
}
/* show record separator for unaligned text */
else
if
(
strcmp
(
param
,
"recordsep"
)
==
0
)
{
if
(
popt
->
topt
.
recordSep
.
separator_zero
)
printf
(
_
(
"Record separator (%s) is zero byte.
\n
"
),
param
);
else
if
(
strcmp
(
popt
->
topt
.
recordSep
.
separator
,
"
\n
"
)
==
0
)
printf
(
_
(
"Record separator (%s) is <newline>.
\n
"
),
param
);
else
printf
(
_
(
"Record separator (%s) is
\"
%s
\"
.
\n
"
),
param
,
popt
->
topt
.
recordSep
.
separator
);
}
else
if
(
strcmp
(
param
,
"recordsep_zero"
)
==
0
)
{
printf
(
_
(
"Record separator (%s) is zero byte.
\n
"
),
param
);
}
/* show HTML table tag options */
else
if
(
strcmp
(
param
,
"T"
)
==
0
||
strcmp
(
param
,
"tableattr"
)
==
0
)
{
if
(
popt
->
topt
.
tableAttr
)
printf
(
_
(
"Table attribute (%s) is
\"
%s
\"
.
\n
"
),
param
,
popt
->
topt
.
tableAttr
);
else
printf
(
_
(
"Table attributes (%s) unset.
\n
"
),
param
);
}
if
(
!
quiet
)
printf
(
_
(
"Target width is %d.
\n
"
),
popt
->
topt
.
columns
);
/* show title override */
else
if
(
strcmp
(
param
,
"title"
)
==
0
)
{
if
(
popt
->
title
)
printf
(
_
(
"Title (%s) is
\"
%s
\"
.
\n
"
),
param
,
popt
->
title
);
else
printf
(
_
(
"Title (%s) unset.
\n
"
),
param
);
}
/* show toggle between full and tuples-only format */
else
if
(
strcmp
(
param
,
"t"
)
==
0
||
strcmp
(
param
,
"tuples_only"
)
==
0
)
{
if
(
popt
->
topt
.
tuples_only
)
printf
(
_
(
"Tuples only (%s) is on.
\n
"
),
param
);
else
printf
(
_
(
"Tuples only (%s) is off.
\n
"
),
param
);
}
else
...
...
src/bin/psql/help.c
View file @
c64e68fd
...
...
@@ -247,7 +247,7 @@ slashUsage(unsigned short int pager)
fprintf
(
output
,
_
(
"
\\
f [STRING] show or set field separator for unaligned query output
\n
"
));
fprintf
(
output
,
_
(
"
\\
H toggle HTML output mode (currently %s)
\n
"
),
ON
(
pset
.
popt
.
topt
.
format
==
PRINT_HTML
));
fprintf
(
output
,
_
(
"
\\
pset
NAME [VALUE
] set table output option
\n
"
fprintf
(
output
,
_
(
"
\\
pset
[NAME [VALUE]
] set table output option
\n
"
" (NAME := {format|border|expanded|fieldsep|fieldsep_zero|footer|null|
\n
"
" numericlocale|recordsep|recordsep_zero|tuples_only|title|tableattr|pager})
\n
"
));
fprintf
(
output
,
_
(
"
\\
t [on|off] show only rows (currently %s)
\n
"
),
...
...
src/test/regress/expected/psql.out
View file @
c64e68fd
...
...
@@ -52,3 +52,19 @@ more than one row returned for \gset
select 10 as test01, 20 as test02 from generate_series(1,0) \gset
no rows returned for \gset
\unset FETCH_COUNT
-- show all pset options
\pset
Border style (border) is 1.
Target width (columns) unset.
Expanded display (expanded) is off.
Field separator (fieldsep) is "|".
Default footer (footer) is on.
Output format (format) is aligned.
Line style (linestyle) is ascii.
Null display (null) is "".
Locale-adjusted numeric output (numericlocale) is off.
Pager (pager) is used for long output.
Record separator (recordsep) is <newline>.
Table attributes (tableattr) unset.
Title (title) unset.
Tuples only (tuples_only) is off.
src/test/regress/sql/psql.sql
View file @
c64e68fd
...
...
@@ -37,3 +37,6 @@ select 10 as test01, 20 as test02 from generate_series(1,3) \gset
select
10
as
test01
,
20
as
test02
from
generate_series
(
1
,
0
)
\
gset
\
unset
FETCH_COUNT
-- show all pset options
\
pset
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment