Skip to content

Commit b54faa1

Browse files
committed
oidvectortypes: use SQL type names and separate by commas
psql \df: use format_type and oidvectortypes map type REAL to float4, not float8 psql \dd :work around UNION bug
1 parent f907712 commit b54faa1

File tree

5 files changed

+112
-86
lines changed

5 files changed

+112
-86
lines changed

src/backend/parser/gram.y

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.176 2000/07/07 19:24:35 petere Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.177 2000/07/09 21:30:10 petere Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -3944,7 +3944,7 @@ Numeric: FLOAT opt_float
39443944
;
39453945

39463946
numeric: FLOAT { $$ = xlateSqlType("float"); }
3947-
| DOUBLE PRECISION { $$ = xlateSqlType("float"); }
3947+
| DOUBLE PRECISION { $$ = xlateSqlType("float8"); }
39483948
| DECIMAL { $$ = xlateSqlType("decimal"); }
39493949
| DEC { $$ = xlateSqlType("decimal"); }
39503950
| NUMERIC { $$ = xlateSqlType("numeric"); }
@@ -5781,8 +5781,9 @@ xlateSqlType(char *name)
57815781
return "int2";
57825782
else if (strcmp(name, "bigint") == 0)
57835783
return "int8";
5784-
else if ((strcmp(name, "real") == 0)
5785-
|| (strcmp(name, "float") == 0))
5784+
else if (strcmp(name, "real") == 0)
5785+
return "float4";
5786+
else if (strcmp(name, "float") == 0)
57865787
return "float8";
57875788
else if (strcmp(name, "decimal") == 0)
57885789
return "numeric";

src/backend/utils/adt/format_type.c

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.1 2000/07/07 19:24:37 petere Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.2 2000/07/09 21:30:12 petere Exp $ */
22

33
#include "postgres.h"
44

@@ -12,6 +12,7 @@
1212

1313
#define streq(a, b) (strcmp((a), (b))==0)
1414
#define MAX_INT32_LEN 11
15+
#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
1516

1617

1718
static char *
@@ -30,7 +31,9 @@ psnprintf(size_t len, const char * fmt, ...)
3031
}
3132

3233

33-
#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
34+
static char *
35+
format_type_internal(Oid type_oid, int32 typemod, bool with_typemod);
36+
3437

3538

3639
/*
@@ -51,15 +54,10 @@ psnprintf(size_t len, const char * fmt, ...)
5154
Datum
5255
format_type(PG_FUNCTION_ARGS)
5356
{
54-
Oid type_oid;
55-
bool with_typemod;
56-
int32 typemod = 0;
57-
char * buf;
58-
char * name;
59-
Oid array_base_type;
60-
int16 typlen;
61-
bool is_array;
62-
HeapTuple tuple;
57+
Oid type_oid;
58+
bool with_typemod;
59+
int32 typemod = 0;
60+
char *result;
6361

6462
if (PG_ARGISNULL(0))
6563
PG_RETURN_NULL();
@@ -70,11 +68,31 @@ format_type(PG_FUNCTION_ARGS)
7068
if (with_typemod)
7169
typemod = PG_GETARG_INT32(1);
7270

71+
result = format_type_internal(type_oid, typemod, with_typemod);
72+
73+
PG_RETURN_TEXT_P(_textin(result));
74+
}
75+
76+
77+
78+
static char *
79+
format_type_internal(Oid type_oid, int32 typemod, bool with_typemod)
80+
{
81+
HeapTuple tuple;
82+
Oid array_base_type;
83+
int16 typlen;
84+
bool is_array;
85+
char *name;
86+
char *buf;
87+
88+
if (type_oid == InvalidOid)
89+
return "-";
90+
7391
tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(type_oid),
7492
0, 0, 0);
7593

7694
if (!HeapTupleIsValid(tuple))
77-
PG_RETURN_TEXT_P(_textin("???"));
95+
return "???";
7896

7997
array_base_type = ((Form_pg_type) GETSTRUCT(tuple))->typelem;
8098
typlen = ((Form_pg_type) GETSTRUCT(tuple))->typlen;
@@ -84,15 +102,15 @@ format_type(PG_FUNCTION_ARGS)
84102
ObjectIdGetDatum(array_base_type),
85103
0, 0, 0);
86104
if (!HeapTupleIsValid(tuple))
87-
PG_RETURN_TEXT_P(_textin("???[]"));
105+
return "???[]";
88106
is_array = true;
89107
}
90108
else
91109
is_array = false;
92110

93-
94111
name = NameStr(((Form_pg_type) GETSTRUCT(tuple))->typname);
95112

113+
96114
if (streq(name, "bit"))
97115
{
98116
if (with_typemod)
@@ -116,14 +134,13 @@ format_type(PG_FUNCTION_ARGS)
116134
* double-quote it to get at it in the parser. */
117135
else if (streq(name, "char"))
118136
buf = pstrdup("\"char\"");
119-
#if 0
120-
/* The parser has these backwards, so leave as is for now. */
137+
121138
else if (streq(name, "float4"))
122139
buf = pstrdup("real");
123140

124141
else if (streq(name, "float8"))
125142
buf = pstrdup("double precision");
126-
#endif
143+
127144
else if (streq(name, "int2"))
128145
buf = pstrdup("smallint");
129146

@@ -177,5 +194,60 @@ format_type(PG_FUNCTION_ARGS)
177194
buf = buf2;
178195
}
179196

180-
PG_RETURN_TEXT_P(_textin(buf));
197+
return buf;
198+
}
199+
200+
201+
202+
/*
203+
* oidvectortypes - converts a vector of type OIDs to "typname" list
204+
*
205+
* The interface for this function is wrong: it should be told how many
206+
* OIDs are significant in the input vector, so that trailing InvalidOid
207+
* argument types can be recognized.
208+
*/
209+
Datum
210+
oidvectortypes(PG_FUNCTION_ARGS)
211+
{
212+
int numargs;
213+
int num;
214+
Oid *oidArray = (Oid *) PG_GETARG_POINTER(0);
215+
char *result;
216+
size_t total;
217+
size_t left;
218+
219+
/* Try to guess how many args there are :-( */
220+
numargs = 0;
221+
for (num = 0; num < FUNC_MAX_ARGS; num++)
222+
{
223+
if (oidArray[num] != InvalidOid)
224+
numargs = num + 1;
225+
}
226+
227+
total = 20 * numargs + 1;
228+
result = palloc(total);
229+
result[0] = '\0';
230+
left = total - 1;
231+
232+
for (num = 0; num < numargs; num++)
233+
{
234+
char * typename = format_type_internal(oidArray[num], 0, false);
235+
236+
if (left < strlen(typename) + 2)
237+
{
238+
total += strlen(typename) + 2;
239+
result = repalloc(result, total);
240+
left += strlen(typename) + 2;
241+
}
242+
243+
if (num > 0)
244+
{
245+
strcat(result, ", ");
246+
left -= 2;
247+
}
248+
strcat(result, typename);
249+
left -= strlen(typename);
250+
}
251+
252+
PG_RETURN_TEXT_P(_textin(result));
181253
}

src/backend/utils/adt/regproc.c

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.57 2000/07/03 23:09:52 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.58 2000/07/09 21:30:12 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -238,53 +238,6 @@ regprocout(PG_FUNCTION_ARGS)
238238
PG_RETURN_CSTRING(result);
239239
}
240240

241-
/*
242-
* oidvectortypes - converts a vector of type OIDs to "typname" list
243-
*
244-
* The interface for this function is wrong: it should be told how many
245-
* OIDs are significant in the input vector, so that trailing InvalidOid
246-
* argument types can be recognized.
247-
*/
248-
Datum
249-
oidvectortypes(PG_FUNCTION_ARGS)
250-
{
251-
Oid *oidArray = (Oid *) PG_GETARG_POINTER(0);
252-
HeapTuple typetup;
253-
text *result;
254-
int numargs,
255-
num;
256-
257-
/* Try to guess how many args there are :-( */
258-
numargs = 0;
259-
for (num = 0; num < FUNC_MAX_ARGS; num++)
260-
{
261-
if (oidArray[num] != InvalidOid)
262-
numargs = num + 1;
263-
}
264-
265-
result = (text *) palloc((NAMEDATALEN + 1) * numargs + VARHDRSZ + 1);
266-
*VARDATA(result) = '\0';
267-
268-
for (num = 0; num < numargs; num++)
269-
{
270-
typetup = SearchSysCacheTuple(TYPEOID,
271-
ObjectIdGetDatum(oidArray[num]),
272-
0, 0, 0);
273-
if (HeapTupleIsValid(typetup))
274-
{
275-
char *s;
276-
277-
s = NameStr(((Form_pg_type) GETSTRUCT(typetup))->typname);
278-
StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s,
279-
NAMEDATALEN);
280-
strcat(VARDATA(result), " ");
281-
}
282-
else
283-
strcat(VARDATA(result), "- ");
284-
}
285-
VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
286-
PG_RETURN_TEXT_P(result);
287-
}
288241

289242

290243
/*****************************************************************************

src/bin/psql/describe.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.22 2000/07/07 19:24:38 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.23 2000/07/09 21:30:19 petere Exp $
77
*/
88
#include "postgres.h"
99
#include "describe.h"
@@ -103,21 +103,21 @@ describeFunctions(const char *name, bool verbose)
103103
* arguments, but have no types defined for those arguments
104104
*/
105105
strcpy(buf,
106-
"SELECT t.typname as \"Result\", p.proname as \"Function\",\n"
106+
"SELECT format_type(p.prorettype, NULL) as \"Result\", p.proname as \"Function\",\n"
107107
" oidvectortypes(p.proargtypes) as \"Arguments\"");
108108
if (verbose)
109109
strcat(buf, ",\n u.usename as \"Owner\", l.lanname as \"Language\", p.prosrc as \"Source\",\n"
110110
" obj_description(p.oid) as \"Description\"");
111111

112112
if (!verbose)
113113
strcat(buf,
114-
"\nFROM pg_proc p, pg_type t\n"
115-
"WHERE p.prorettype = t.oid and (pronargs = 0 or oidvectortypes(p.proargtypes) != '')\n");
114+
"\nFROM pg_proc p\n"
115+
"WHERE p.prorettype <> 0 and (pronargs = 0 or oidvectortypes(p.proargtypes) <> '')\n");
116116
else
117117
strcat(buf,
118-
"\nFROM pg_proc p, pg_type t, pg_language l, pg_user u\n"
119-
"WHERE p.prorettype = t.oid AND p.prolang = l.oid AND p.proowner = u.usesysid\n"
120-
" AND (pronargs = 0 or oidvectortypes(p.proargtypes) != '')\n");
118+
"\nFROM pg_proc p, pg_language l, pg_user u\n"
119+
"WHERE p.prolang = l.oid AND p.proowner = u.usesysid\n"
120+
" AND p.prorettype <> 0 and (pronargs = 0 or oidvectortypes(p.proargtypes) <> '')\n");
121121

122122
if (name)
123123
{
@@ -380,7 +380,7 @@ objectDescription(const char *object)
380380
descbuf[0] = '\0';
381381

382382
/* Aggregate descriptions */
383-
strcat(descbuf, "SELECT DISTINCT a.aggname as \"Name\", 'aggregate'::text as \"Object\", d.description as \"Description\"\n"
383+
strcat(descbuf, "SELECT DISTINCT a.aggname::text as \"Name\", 'aggregate'::text as \"Object\", d.description as \"Description\"\n"
384384
"FROM pg_aggregate a, pg_description d\n"
385385
"WHERE a.oid = d.objoid\n");
386386
if (object)
@@ -392,7 +392,7 @@ objectDescription(const char *object)
392392

393393
/* Function descriptions (except in/outs for datatypes) */
394394
strcat(descbuf, "\nUNION ALL\n\n");
395-
strcat(descbuf, "SELECT DISTINCT p.proname as \"Name\", 'function'::text as \"Object\", d.description as \"Description\"\n"
395+
strcat(descbuf, "SELECT DISTINCT p.proname::text as \"Name\", 'function'::text as \"Object\", d.description as \"Description\"\n"
396396
"FROM pg_proc p, pg_description d\n"
397397
"WHERE p.oid = d.objoid AND (p.pronargs = 0 or oidvectortypes(p.proargtypes) != '')\n");
398398
if (object)
@@ -404,7 +404,7 @@ objectDescription(const char *object)
404404

405405
/* Operator descriptions */
406406
strcat(descbuf, "\nUNION ALL\n\n");
407-
strcat(descbuf, "SELECT DISTINCT o.oprname as \"Name\", 'operator'::text as \"Object\", d.description as \"Description\"\n"
407+
strcat(descbuf, "SELECT DISTINCT o.oprname::text as \"Name\", 'operator'::text as \"Object\", d.description as \"Description\"\n"
408408
"FROM pg_operator o, pg_description d\n"
409409
/* must get comment via associated function */
410410
"WHERE RegprocToOid(o.oprcode) = d.objoid\n");
@@ -429,7 +429,7 @@ objectDescription(const char *object)
429429

430430
/* Relation (tables, views, indices, sequences) descriptions */
431431
strcat(descbuf, "\nUNION ALL\n\n");
432-
strcat(descbuf, "SELECT DISTINCT c.relname as \"Name\", 'relation'::text||'('||c.relkind||')' as \"Object\", d.description as \"Description\"\n"
432+
strcat(descbuf, "SELECT DISTINCT c.relname::text as \"Name\", 'relation'::text||'('||c.relkind||')' as \"Object\", d.description as \"Description\"\n"
433433
"FROM pg_class c, pg_description d\n"
434434
"WHERE c.oid = d.objoid\n");
435435
if (object)
@@ -441,7 +441,7 @@ objectDescription(const char *object)
441441

442442
/* Rule description (ignore rules for views) */
443443
strcat(descbuf, "\nUNION ALL\n\n");
444-
strcat(descbuf, "SELECT DISTINCT r.rulename as \"Name\", 'rule'::text as \"Object\", d.description as \"Description\"\n"
444+
strcat(descbuf, "SELECT DISTINCT r.rulename::text as \"Name\", 'rule'::text as \"Object\", d.description as \"Description\"\n"
445445
"FROM pg_rewrite r, pg_description d\n"
446446
"WHERE r.oid = d.objoid AND r.rulename !~ '^_RET'\n");
447447
if (object)
@@ -453,7 +453,7 @@ objectDescription(const char *object)
453453

454454
/* Trigger description */
455455
strcat(descbuf, "\nUNION ALL\n\n");
456-
strcat(descbuf, "SELECT DISTINCT t.tgname as \"Name\", 'trigger'::text as \"Object\", d.description as \"Description\"\n"
456+
strcat(descbuf, "SELECT DISTINCT t.tgname::text as \"Name\", 'trigger'::text as \"Object\", d.description as \"Description\"\n"
457457
"FROM pg_trigger t, pg_description d\n"
458458
"WHERE t.oid = d.objoid\n");
459459
if (object)

src/include/utils/builtins.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: builtins.h,v 1.122 2000/07/08 03:04:36 tgl Exp $
10+
* $Id: builtins.h,v 1.123 2000/07/09 21:30:21 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -325,7 +325,6 @@ extern Datum texticregexne(PG_FUNCTION_ARGS);
325325
/* regproc.c */
326326
extern Datum regprocin(PG_FUNCTION_ARGS);
327327
extern Datum regprocout(PG_FUNCTION_ARGS);
328-
extern Datum oidvectortypes(PG_FUNCTION_ARGS);
329328
extern Datum regproctooid(PG_FUNCTION_ARGS);
330329

331330
/* define macro to replace mixed-case function call - tgl 97/04/27 */
@@ -601,7 +600,8 @@ extern Datum getdatabaseencoding(PG_FUNCTION_ARGS);
601600
extern Datum PG_encoding_to_char(PG_FUNCTION_ARGS);
602601
extern Datum PG_char_to_encoding(PG_FUNCTION_ARGS);
603602

604-
/* formatting for internal types */
603+
/* format_type.c */
605604
extern Datum format_type(PG_FUNCTION_ARGS);
605+
extern Datum oidvectortypes(PG_FUNCTION_ARGS);
606606

607607
#endif /* BUILTINS_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy