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
9f4e9bfa
Commit
9f4e9bfa
authored
May 05, 2009
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code review for \df rewrite: fix assorted bugs, make type and
volatility columns localizable.
parent
0e198848
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
32 deletions
+59
-32
src/bin/psql/describe.c
src/bin/psql/describe.c
+59
-32
No files found.
src/bin/psql/describe.c
View file @
9f4e9bfa
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.21
1 2009/05/04 17:31:35 heikki
Exp $
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.21
2 2009/05/05 02:29:06 tgl
Exp $
*/
*/
#include "postgres_fe.h"
#include "postgres_fe.h"
...
@@ -197,14 +197,15 @@ describeTablespaces(const char *pattern, bool verbose)
...
@@ -197,14 +197,15 @@ describeTablespaces(const char *pattern, bool verbose)
bool
bool
describeFunctions
(
const
char
*
functypes
,
const
char
*
pattern
,
bool
verbose
,
bool
showSystem
)
describeFunctions
(
const
char
*
functypes
,
const
char
*
pattern
,
bool
verbose
,
bool
showSystem
)
{
{
bool
showAggregate
=
strchr
(
functypes
,
'a'
)
!=
NULL
;
bool
showAggregate
=
strchr
(
functypes
,
'a'
)
!=
NULL
;
bool
showNormal
=
strchr
(
functypes
,
'n'
)
!=
NULL
;
bool
showNormal
=
strchr
(
functypes
,
'n'
)
!=
NULL
;
bool
showTrigger
=
strchr
(
functypes
,
't'
)
!=
NULL
;
bool
showTrigger
=
strchr
(
functypes
,
't'
)
!=
NULL
;
bool
showWindow
=
strchr
(
functypes
,
'w'
)
!=
NULL
;
bool
showWindow
=
strchr
(
functypes
,
'w'
)
!=
NULL
;
bool
have_where
;
PQExpBufferData
buf
;
PQExpBufferData
buf
;
PGresult
*
res
;
PGresult
*
res
;
printQueryOpt
myopt
=
pset
.
popt
;
printQueryOpt
myopt
=
pset
.
popt
;
static
const
bool
translate_columns
[]
=
{
false
,
false
,
false
,
false
,
true
,
true
,
false
,
false
,
false
,
false
};
if
(
strlen
(
functypes
)
!=
strspn
(
functypes
,
"antwS+"
))
if
(
strlen
(
functypes
)
!=
strspn
(
functypes
,
"antwS+"
))
{
{
...
@@ -241,7 +242,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
...
@@ -241,7 +242,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
" CASE
\n
"
" CASE
\n
"
" WHEN p.proisagg THEN '%s'
\n
"
" WHEN p.proisagg THEN '%s'
\n
"
" WHEN p.proiswindow THEN '%s'
\n
"
" WHEN p.proiswindow THEN '%s'
\n
"
" WHEN p
g_catalog.pg_get_function_result(p.oid) = 'trigger'
THEN '%s'
\n
"
" WHEN p
.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype
THEN '%s'
\n
"
" ELSE '%s'
\n
"
" ELSE '%s'
\n
"
"END as
\"
%s
\"
"
,
"END as
\"
%s
\"
"
,
gettext_noop
(
"Result data type"
),
gettext_noop
(
"Result data type"
),
...
@@ -287,7 +288,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
...
@@ -287,7 +288,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
" END AS
\"
%s
\"
,
\n
"
" END AS
\"
%s
\"
,
\n
"
" CASE
\n
"
" CASE
\n
"
" WHEN p.proisagg THEN '%s'
\n
"
" WHEN p.proisagg THEN '%s'
\n
"
" WHEN
'trigger' = pg_catalog.format_type(p.prorettype, NULL)
THEN '%s'
\n
"
" WHEN
p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype
THEN '%s'
\n
"
" ELSE '%s'
\n
"
" ELSE '%s'
\n
"
" END AS
\"
%s
\"
"
,
" END AS
\"
%s
\"
"
,
gettext_noop
(
"Result data type"
),
gettext_noop
(
"Result data type"
),
...
@@ -304,7 +305,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
...
@@ -304,7 +305,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
" pg_catalog.oidvectortypes(p.proargtypes) as
\"
%s
\"
,
\n
"
" pg_catalog.oidvectortypes(p.proargtypes) as
\"
%s
\"
,
\n
"
" CASE
\n
"
" CASE
\n
"
" WHEN p.proisagg THEN '%s'
\n
"
" WHEN p.proisagg THEN '%s'
\n
"
" WHEN
'trigger' = pg_catalog.format_type(p.prorettype, NULL)
THEN '%s'
\n
"
" WHEN
p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype
THEN '%s'
\n
"
" ELSE '%s'
\n
"
" ELSE '%s'
\n
"
" END AS
\"
%s
\"
"
,
" END AS
\"
%s
\"
"
,
gettext_noop
(
"Result data type"
),
gettext_noop
(
"Result data type"
),
...
@@ -318,14 +319,17 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
...
@@ -318,14 +319,17 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
if
(
verbose
)
if
(
verbose
)
appendPQExpBuffer
(
&
buf
,
appendPQExpBuffer
(
&
buf
,
",
\n
CASE
\n
"
",
\n
CASE
\n
"
" WHEN p.provolatile = 'i' THEN '
immutable
'
\n
"
" WHEN p.provolatile = 'i' THEN '
%s
'
\n
"
" WHEN p.provolatile = 's' THEN '
stable
'
\n
"
" WHEN p.provolatile = 's' THEN '
%s
'
\n
"
" WHEN p.provolatile = 'v' THEN '
volatile
'
\n
"
" WHEN p.provolatile = 'v' THEN '
%s
'
\n
"
"END as
\"
%s
\"
"
"END as
\"
%s
\"
"
",
\n
pg_catalog.pg_get_userbyid(p.proowner) as
\"
%s
\"
,
\n
"
",
\n
pg_catalog.pg_get_userbyid(p.proowner) as
\"
%s
\"
,
\n
"
" l.lanname as
\"
%s
\"
,
\n
"
" l.lanname as
\"
%s
\"
,
\n
"
" p.prosrc as
\"
%s
\"
,
\n
"
" p.prosrc as
\"
%s
\"
,
\n
"
" pg_catalog.obj_description(p.oid, 'pg_proc') as
\"
%s
\"
"
,
" pg_catalog.obj_description(p.oid, 'pg_proc') as
\"
%s
\"
"
,
gettext_noop
(
"immutable"
),
gettext_noop
(
"stable"
),
gettext_noop
(
"volatile"
),
gettext_noop
(
"Volatility"
),
gettext_noop
(
"Volatility"
),
gettext_noop
(
"Owner"
),
gettext_noop
(
"Owner"
),
gettext_noop
(
"Language"
),
gettext_noop
(
"Language"
),
...
@@ -340,33 +344,54 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
...
@@ -340,33 +344,54 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
appendPQExpBuffer
(
&
buf
,
appendPQExpBuffer
(
&
buf
,
" LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang
\n
"
);
" LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang
\n
"
);
processSQLNamePattern
(
pset
.
db
,
&
buf
,
pattern
,
false
,
true
,
have_where
=
false
;
"n.nspname"
,
"p.proname"
,
NULL
,
"pg_catalog.pg_function_is_visible(p.oid)"
);
/* filter by function type, if requested */
if
(
showNormal
&&
showAggregate
&&
showTrigger
&&
showWindow
)
if
(
showNormal
&&
showAggregate
&&
showTrigger
&&
showWindow
)
/* Do nothing */
;
/* Do nothing */
;
else
if
(
showNormal
)
else
if
(
showNormal
)
{
{
if
(
!
showWindow
&&
pset
.
sversion
>=
80400
)
appendPQExpBuffer
(
&
buf
,
" AND NOT p.proiswindow
\n
"
);
if
(
!
showAggregate
)
if
(
!
showAggregate
)
appendPQExpBuffer
(
&
buf
,
" AND NOT p.proisagg
\n
"
);
{
if
(
have_where
)
appendPQExpBuffer
(
&
buf
,
" AND "
);
else
{
appendPQExpBuffer
(
&
buf
,
"WHERE "
);
have_where
=
true
;
}
appendPQExpBuffer
(
&
buf
,
"NOT p.proisagg
\n
"
);
}
if
(
!
showTrigger
)
if
(
!
showTrigger
)
{
{
if
(
pset
.
sversion
>=
80400
)
if
(
have_where
)
appendPQExpBuffer
(
&
buf
,
appendPQExpBuffer
(
&
buf
,
" AND "
);
" AND pg_catalog.pg_get_function_result(p.oid) <> 'trigger'
\n
"
);
else
else
appendPQExpBuffer
(
&
buf
,
{
" AND pg_catalog.format_type(p.prorettype, NULL) <> 'trigger'
\n
"
);
appendPQExpBuffer
(
&
buf
,
"WHERE "
);
have_where
=
true
;
}
appendPQExpBuffer
(
&
buf
,
"p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype
\n
"
);
}
if
(
!
showWindow
&&
pset
.
sversion
>=
80400
)
{
if
(
have_where
)
appendPQExpBuffer
(
&
buf
,
" AND "
);
else
{
appendPQExpBuffer
(
&
buf
,
"WHERE "
);
have_where
=
true
;
}
appendPQExpBuffer
(
&
buf
,
"NOT p.proiswindow
\n
"
);
}
}
}
}
else
else
{
{
bool
needs_or
=
false
;
bool
needs_or
=
false
;
appendPQExpBuffer
(
&
buf
,
" AND (
\n
"
);
appendPQExpBuffer
(
&
buf
,
"WHERE (
\n
"
);
have_where
=
true
;
/* Note: at least one of these must be true ... */
if
(
showAggregate
)
if
(
showAggregate
)
{
{
appendPQExpBuffer
(
&
buf
,
"p.proisagg
\n
"
);
appendPQExpBuffer
(
&
buf
,
"p.proisagg
\n
"
);
...
@@ -375,24 +400,25 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
...
@@ -375,24 +400,25 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
if
(
showTrigger
)
if
(
showTrigger
)
{
{
if
(
needs_or
)
if
(
needs_or
)
appendPQExpBuffer
(
&
buf
,
" OR "
);
appendPQExpBuffer
(
&
buf
,
" OR "
);
if
(
pset
.
sversion
>=
80400
)
appendPQExpBuffer
(
&
buf
,
appendPQExpBuffer
(
&
buf
,
"p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype
\n
"
);
"pg_catalog.pg_get_function_result(p.oid) = 'trigger'
\n
"
);
else
appendPQExpBuffer
(
&
buf
,
"'trigger' <> pg_catalog.format_type(p.prorettype, NULL)
\n
"
);
needs_or
=
true
;
needs_or
=
true
;
}
}
if
(
showWindow
)
if
(
showWindow
)
{
{
if
(
needs_or
)
if
(
needs_or
)
appendPQExpBuffer
(
&
buf
,
" OR "
);
appendPQExpBuffer
(
&
buf
,
"
OR "
);
appendPQExpBuffer
(
&
buf
,
"p.proiswindow
\n
"
);
appendPQExpBuffer
(
&
buf
,
"p.proiswindow
\n
"
);
needs_or
=
true
;
}
}
appendPQExpBuffer
(
&
buf
,
" )
\n
"
);
appendPQExpBuffer
(
&
buf
,
" )
\n
"
);
}
}
processSQLNamePattern
(
pset
.
db
,
&
buf
,
pattern
,
have_where
,
true
,
"n.nspname"
,
"p.proname"
,
NULL
,
"pg_catalog.pg_function_is_visible(p.oid)"
);
if
(
!
showSystem
&&
!
pattern
)
if
(
!
showSystem
&&
!
pattern
)
appendPQExpBuffer
(
&
buf
,
" AND n.nspname <> 'pg_catalog'
\n
"
appendPQExpBuffer
(
&
buf
,
" AND n.nspname <> 'pg_catalog'
\n
"
" AND n.nspname <> 'information_schema'
\n
"
);
" AND n.nspname <> 'information_schema'
\n
"
);
...
@@ -407,6 +433,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
...
@@ -407,6 +433,7 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
myopt
.
nullPrint
=
NULL
;
myopt
.
nullPrint
=
NULL
;
myopt
.
title
=
_
(
"List of functions"
);
myopt
.
title
=
_
(
"List of functions"
);
myopt
.
translate_header
=
true
;
myopt
.
translate_header
=
true
;
myopt
.
translate_columns
=
translate_columns
;
printQuery
(
res
,
&
myopt
,
pset
.
queryFout
,
pset
.
logfile
);
printQuery
(
res
,
&
myopt
,
pset
.
queryFout
,
pset
.
logfile
);
...
...
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