> > > This patches src/bin/psql/psql.c.
authorBruce Momjian <bruce@momjian.us>
Mon, 15 Mar 1999 02:18:37 +0000 (02:18 +0000)
committerBruce Momjian <bruce@momjian.us>
Mon, 15 Mar 1999 02:18:37 +0000 (02:18 +0000)
> > >
> > > This patch is in responce to the following TODO list item:
> > >  * have psql \d on a view show the query
> > > -Ryan

src/backend/utils/adt/like.c
src/bin/psql/psql.c

index 1b2b9cc1c5fa4eeab121f1373a39fa5208720324..e3d37739a9f99d9325816e5d9a07a0dc9944b31f 100644 (file)
@@ -23,7 +23,7 @@
 #include "utils/builtins.h"        /* where the function declarations go */
 #include "mb/pg_wchar.h"
 
-static int like(pg_wchar * text, pg_wchar * p);
+static int like(pg_wchar *text, pg_wchar *p);
 
 /*
  * interface routines called by the function manager
@@ -38,7 +38,7 @@ static int    like(pg_wchar * text, pg_wchar * p);
         charlen   - the length of the string
 */
 static bool
-fixedlen_like(char *s, struct varlena * p, int charlen)
+fixedlen_like(char *s, struct varlena *p, int charlen)
 {
    pg_wchar   *sterm,
               *pterm;
@@ -83,7 +83,7 @@ fixedlen_like(char *s, struct varlena * p, int charlen)
 }
 
 bool
-namelike(NameData *n, struct varlena * p)
+namelike(NameData *n, struct varlena *p)
 {
    if (!n)
        return FALSE;
@@ -91,13 +91,13 @@ namelike(NameData *n, struct varlena * p)
 }
 
 bool
-namenlike(NameData *s, struct varlena * p)
+namenlike(NameData *s, struct varlena *p)
 {
    return !namelike(s, p);
 }
 
 bool
-textlike(struct varlena * s, struct varlena * p)
+textlike(struct varlena *s, struct varlena *p)
 {
    if (!s)
        return FALSE;
@@ -105,13 +105,13 @@ textlike(struct varlena * s, struct varlena * p)
 }
 
 bool
-textnlike(struct varlena * s, struct varlena * p)
+textnlike(struct varlena *s, struct varlena *p)
 {
    return !textlike(s, p);
 }
 
 
-/* $Revision: 1.21 $
+/* $Revision: 1.22 $
 ** "like.c" A first attempt at a LIKE operator for Postgres95.
 **
 ** Originally written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.
@@ -146,7 +146,7 @@ textnlike(struct varlena * s, struct varlena * p)
 ** Match text and p, return LIKE_TRUE, LIKE_FALSE, or LIKE_ABORT.
 */
 static int
-DoMatch(pg_wchar * text, pg_wchar * p)
+DoMatch(pg_wchar *text, pg_wchar *p)
 {
    int         matched;
 
@@ -189,7 +189,7 @@ DoMatch(pg_wchar * text, pg_wchar * p)
 ** User-level routine.  Returns TRUE or FALSE.
 */
 static int
-like(pg_wchar * text, pg_wchar * p)
+like(pg_wchar *text, pg_wchar *p)
 {
    if (p[0] == '%' && p[1] == '\0')
        return TRUE;
index 5de5a2a83fb63da462be630cbad7585959366c9c..524ab61e9722ff44859f99129ed92bb3c46077c6 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.171 1999/02/21 03:49:39 scrappy Exp $
+ *   $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.172 1999/03/15 02:18:37 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -760,11 +760,35 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
                fout = stdout;
        }
 
+       /*
+        * Extract the veiw name and veiw definition from pg_views.
+                 * -Ryan 2/14/99
+        */
+
+       descbuf[0] = '\0';
+       strcat(descbuf, "SELECT viewname, definition ");
+       strcat(descbuf, "FROM pg_views ");
+       strcat(descbuf, "WHERE viewname like '");
+       strcat(descbuf, table);
+       strcat(descbuf, "' ");
+       if(!(res2 = PSQLexec(pset, descbuf)))
+         return -1;
+
        /*
         * Display the information
         */
+       if(PQntuples(res2)) {
+         /*
+          * display the query.
+          * -Ryan 2/14/99
+          */
+         fprintf(fout, "\nView    = %s\n", table);
+         fprintf(fout, "Query   = %s\n", PQgetvalue(res2, 0, 1));
+       } else {
+         fprintf(fout, "\nTable    = %s\n", table);
+       }
+       PQclear(res2);
 
-       fprintf(fout, "\nTable    = %s\n", table);
        fprintf(fout, "+----------------------------------+----------------------------------+-------+\n");
        fprintf(fout, "|              Field               |              Type                | Length|\n");
        fprintf(fout, "+----------------------------------+----------------------------------+-------+\n");