~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-proposed

« back to all changes in this revision

Viewing changes to src/bin/psql/describe.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-05-19 14:03:37 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090519140337-wp9u2si99uppeb81
Tags: 8.4~beta2-2
* Second public beta of 8.4.
* debian/control: Slightly lower the dependencies for postgresql-common to
  >= 98~, so that backports also match.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 * Copyright (c) 2000-2009, PostgreSQL Global Development Group
10
10
 *
11
 
 * $PostgreSQL$
 
11
 * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.212 2009/05/05 02:29:06 tgl Exp $
12
12
 */
13
13
#include "postgres_fe.h"
14
14
 
197
197
bool
198
198
describeFunctions(const char *functypes, const char *pattern, bool verbose, bool showSystem)
199
199
{
200
 
        bool                    showAggregate = strchr(functypes, 'a') != NULL;
201
 
        bool                    showNormal = strchr(functypes, 'n') != NULL;
202
 
        bool                    showTrigger = strchr(functypes, 't') != NULL;
203
 
        bool                    showWindow = strchr(functypes, 'w') != NULL;
204
 
 
 
200
        bool            showAggregate = strchr(functypes, 'a') != NULL;
 
201
        bool            showNormal = strchr(functypes, 'n') != NULL;
 
202
        bool            showTrigger = strchr(functypes, 't') != NULL;
 
203
        bool            showWindow = strchr(functypes, 'w') != NULL;
 
204
        bool            have_where;
205
205
        PQExpBufferData buf;
206
206
        PGresult   *res;
207
207
        printQueryOpt myopt = pset.popt;
 
208
        static const bool translate_columns[] = {false, false, false, false, true, true, false, false, false, false};
208
209
 
209
210
        if (strlen(functypes) != strspn(functypes, "antwS+"))
210
211
        {
241
242
                                                  " CASE\n"
242
243
                                                  "  WHEN p.proisagg THEN '%s'\n"
243
244
                                                  "  WHEN p.proiswindow THEN '%s'\n"
244
 
                                                  "  WHEN pg_catalog.pg_get_function_result(p.oid) = 'trigger' THEN '%s'\n"
 
245
                                                  "  WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
245
246
                                                  "  ELSE '%s'\n"
246
247
                                                  "END as \"%s\"",
247
248
                                                  gettext_noop("Result data type"),
287
288
                                          "  END AS \"%s\",\n"
288
289
                                          "  CASE\n"
289
290
                                          "    WHEN p.proisagg THEN '%s'\n"
290
 
                                          "    WHEN 'trigger' = pg_catalog.format_type(p.prorettype, NULL) THEN '%s'\n"
 
291
                                          "    WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
291
292
                                          "    ELSE '%s'\n"
292
293
                                          "  END AS \"%s\"",
293
294
                                                  gettext_noop("Result data type"),
304
305
                                          "  pg_catalog.oidvectortypes(p.proargtypes) as \"%s\",\n"
305
306
                                          "  CASE\n"
306
307
                                          "    WHEN p.proisagg THEN '%s'\n"
307
 
                                          "    WHEN 'trigger' = pg_catalog.format_type(p.prorettype, NULL) THEN '%s'\n"
 
308
                                          "    WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
308
309
                                          "    ELSE '%s'\n"
309
310
                                          "  END AS \"%s\"",
310
311
                                                  gettext_noop("Result data type"),
318
319
        if (verbose)
319
320
                appendPQExpBuffer(&buf,
320
321
                                                  ",\n CASE\n"
321
 
                                                  "  WHEN p.provolatile = 'i' THEN 'immutable'\n"
322
 
                                                  "  WHEN p.provolatile = 's' THEN 'stable'\n"
323
 
                                                  "  WHEN p.provolatile = 'v' THEN 'volatile'\n"
 
322
                                                  "  WHEN p.provolatile = 'i' THEN '%s'\n"
 
323
                                                  "  WHEN p.provolatile = 's' THEN '%s'\n"
 
324
                                                  "  WHEN p.provolatile = 'v' THEN '%s'\n"
324
325
                                                  "END as \"%s\""
325
326
                                                  ",\n  pg_catalog.pg_get_userbyid(p.proowner) as \"%s\",\n"
326
327
                                                  "  l.lanname as \"%s\",\n"
327
328
                                                  "  p.prosrc as \"%s\",\n"
328
329
                                  "  pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
 
330
                                                  gettext_noop("immutable"),
 
331
                                                  gettext_noop("stable"),
 
332
                                                  gettext_noop("volatile"),
329
333
                                                  gettext_noop("Volatility"),
330
334
                                                  gettext_noop("Owner"),
331
335
                                                  gettext_noop("Language"),
340
344
                appendPQExpBuffer(&buf,
341
345
                                                  "     LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
342
346
 
343
 
        processSQLNamePattern(pset.db, &buf, pattern, false, true,
344
 
                                                  "n.nspname", "p.proname", NULL,
345
 
                                                  "pg_catalog.pg_function_is_visible(p.oid)");
 
347
        have_where = false;
346
348
 
 
349
        /* filter by function type, if requested */
347
350
        if (showNormal && showAggregate && showTrigger && showWindow)
348
351
                /* Do nothing */;
349
352
        else if (showNormal)
350
353
        {
351
 
                if (!showWindow && pset.sversion >= 80400)
352
 
                                appendPQExpBuffer(&buf, "      AND NOT p.proiswindow\n");
353
354
                if (!showAggregate)
354
 
                        appendPQExpBuffer(&buf, "      AND NOT p.proisagg\n");
 
355
                {
 
356
                        if (have_where)
 
357
                                appendPQExpBuffer(&buf, "      AND ");
 
358
                        else
 
359
                        {
 
360
                                appendPQExpBuffer(&buf, "WHERE ");
 
361
                                have_where = true;
 
362
                        }
 
363
                        appendPQExpBuffer(&buf, "NOT p.proisagg\n");
 
364
                }
355
365
                if (!showTrigger)
356
366
                {
357
 
                        if (pset.sversion >= 80400)
358
 
                                appendPQExpBuffer(&buf,
359
 
                                                                  "      AND pg_catalog.pg_get_function_result(p.oid) <> 'trigger'\n");
360
 
                        else
361
 
                                appendPQExpBuffer(&buf,
362
 
                                                                  "      AND pg_catalog.format_type(p.prorettype, NULL) <> 'trigger'\n");
 
367
                        if (have_where)
 
368
                                appendPQExpBuffer(&buf, "      AND ");
 
369
                        else
 
370
                        {
 
371
                                appendPQExpBuffer(&buf, "WHERE ");
 
372
                                have_where = true;
 
373
                        }
 
374
                        appendPQExpBuffer(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
 
375
                }
 
376
                if (!showWindow && pset.sversion >= 80400)
 
377
                {
 
378
                        if (have_where)
 
379
                                appendPQExpBuffer(&buf, "      AND ");
 
380
                        else
 
381
                        {
 
382
                                appendPQExpBuffer(&buf, "WHERE ");
 
383
                                have_where = true;
 
384
                        }
 
385
                        appendPQExpBuffer(&buf, "NOT p.proiswindow\n");
363
386
                }
364
387
        }
365
388
        else
366
389
        {
367
390
                bool    needs_or = false;
368
391
 
369
 
                appendPQExpBuffer(&buf, "      AND (\n         ");
 
392
                appendPQExpBuffer(&buf, "WHERE (\n       ");
 
393
                have_where = true;
 
394
                /* Note: at least one of these must be true ... */
370
395
                if (showAggregate)
371
396
                {
372
397
                        appendPQExpBuffer(&buf,"p.proisagg\n");
375
400
                if (showTrigger)
376
401
                {
377
402
                        if (needs_or)
378
 
                                appendPQExpBuffer(&buf, "      OR ");
379
 
                        if (pset.sversion >= 80400)
380
 
                                appendPQExpBuffer(&buf,
381
 
                                                                  "pg_catalog.pg_get_function_result(p.oid) = 'trigger'\n");
382
 
                        else
383
 
                                appendPQExpBuffer(&buf,
384
 
                                                                  "'trigger' <> pg_catalog.format_type(p.prorettype, NULL)\n");
 
403
                                appendPQExpBuffer(&buf, "       OR ");
 
404
                        appendPQExpBuffer(&buf,
 
405
                                                          "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
385
406
                        needs_or = true;
386
407
                }
387
408
                if (showWindow)
388
409
                {
389
410
                        if (needs_or)
390
 
                                appendPQExpBuffer(&buf, "      OR ");
 
411
                                appendPQExpBuffer(&buf, "       OR ");
391
412
                        appendPQExpBuffer(&buf, "p.proiswindow\n");
 
413
                        needs_or = true;
392
414
                }
393
415
                appendPQExpBuffer(&buf, "      )\n");
394
416
        }
395
417
 
 
418
        processSQLNamePattern(pset.db, &buf, pattern, have_where, true,
 
419
                                                  "n.nspname", "p.proname", NULL,
 
420
                                                  "pg_catalog.pg_function_is_visible(p.oid)");
 
421
 
396
422
        if (!showSystem && !pattern)
397
423
                appendPQExpBuffer(&buf, "      AND n.nspname <> 'pg_catalog'\n"
398
424
                                                                "      AND n.nspname <> 'information_schema'\n");
407
433
        myopt.nullPrint = NULL;
408
434
        myopt.title = _("List of functions");
409
435
        myopt.translate_header = true;
 
436
        myopt.translate_columns = translate_columns;
410
437
 
411
438
        printQuery(res, &myopt, pset.queryFout, pset.logfile);
412
439
 
1049
1076
                                                  "%s, reltablespace\n"
1050
1077
                                                  "FROM pg_catalog.pg_class WHERE oid = '%s'",
1051
1078
                                                  (verbose ?
1052
 
                                                   "pg_catalog.array_to_string(reloptions, E', ')" : ",''"),
 
1079
                                                   "pg_catalog.array_to_string(reloptions, E', ')" : "''"),
1053
1080
                                                  oid);
1054
1081
        }
1055
1082
        else if (pset.sversion >= 80000)