Re: [GENERAL] [Help] Temporary Table: Implicitely created index not shown in \d i

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [GENERAL] [Help] Temporary Table: Implicitely created index not shown in \d i
Дата
Msg-id 200106222304.f5MN4Ja05624@candle.pha.pa.us
обсуждение исходный текст
Ответы Re: Re: [GENERAL] [Help] Temporary Table: Implicitely created index not shown in \d i  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-patches
> Hi,
>
> I'm running v7.1.2. In psql, if I
>
>   CREATE TEMPORARY TABLE junk (col1 SERIAL, <more cols>)
>
> and check \ds, the implicitely created sequence is shown but \di doesn't
> show
> the implicitely created index.

OK, here is a patch that fixes it so the sequence is temporary like
everything else.  It also adds CREATE TEMPORARY SEQUENCE to the syntax.

    test=> create temp table kkk(x serial);
    NOTICE:  CREATE TABLE will create implicit sequence 'kkk_x_seq' for
    SERIAL column 'kkk.x'
    NOTICE:  CREATE TABLE/UNIQUE will create implicit index 'kkk_x_key' for
    table 'kkk'
    CREATE
    test=> \d
    No relations found.
    test=> \di
    No relations found.
    test=> \dS
              List of relations
          Name      |   Type   |  Owner
    ----------------+----------+----------
    ...
     pg_temp_5396_0 | sequence | postgres
     pg_temp_5396_1 | table    | postgres

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: doc/src/sgml/ref/create_sequence.sgml
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/doc/src/sgml/ref/create_sequence.sgml,v
retrieving revision 1.15
diff -c -r1.15 create_sequence.sgml
*** doc/src/sgml/ref/create_sequence.sgml    2000/12/08 20:06:58    1.15
--- doc/src/sgml/ref/create_sequence.sgml    2001/06/22 23:02:48
***************
*** 23,29 ****
     <date>1999-07-20</date>
    </refsynopsisdivinfo>
    <synopsis>
! CREATE SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT <replaceable
class="parameter">increment</replaceable>] 
      [ MINVALUE <replaceable class="parameter">minvalue</replaceable> ] [ MAXVALUE <replaceable
class="parameter">maxvalue</replaceable>] 
      [ START <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable
class="parameter">cache</replaceable>] [ CYCLE ] 
    </synopsis>
--- 23,29 ----
     <date>1999-07-20</date>
    </refsynopsisdivinfo>
    <synopsis>
! CREATE [ TEMPORARY | TEMP ] SEQUENCE <replaceable class="parameter">seqname</replaceable> [ INCREMENT <replaceable
class="parameter">increment</replaceable>] 
      [ MINVALUE <replaceable class="parameter">minvalue</replaceable> ] [ MAXVALUE <replaceable
class="parameter">maxvalue</replaceable>] 
      [ START <replaceable class="parameter">start</replaceable> ] [ CACHE <replaceable
class="parameter">cache</replaceable>] [ CYCLE ] 
    </synopsis>
***************
*** 36,41 ****
--- 36,54 ----
      Inputs
     </title>
     <para>
+
+     <variablelist>
+      <varlistentry>
+       <term>TEMPORARY or TEMP</term>
+       <listitem>
+        <para>
+     If specified, the sequence is created only for this session, and is
+     automatically dropped on session exit.
+     Existing permanent sequences with the same name are not visible
+     (in this session) while the temporary sequence exists.
+        </para>
+       </listitem>
+      </varlistentry>

      <variablelist>
       <varlistentry>
Index: src/backend/commands/sequence.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/commands/sequence.c,v
retrieving revision 1.59
diff -c -r1.59 sequence.c
*** src/backend/commands/sequence.c    2001/06/13 21:07:12    1.59
--- src/backend/commands/sequence.c    2001/06/22 23:02:49
***************
*** 161,166 ****
--- 161,167 ----
      }

      stmt->relname = seq->seqname;
+     stmt->istemp = seq->istemp;
      stmt->inhRelnames = NIL;
      stmt->constraints = NIL;

Index: src/backend/parser/analyze.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/parser/analyze.c,v
retrieving revision 1.189
diff -c -r1.189 analyze.c
*** src/backend/parser/analyze.c    2001/06/04 23:27:23    1.189
--- src/backend/parser/analyze.c    2001/06/22 23:02:51
***************
*** 779,784 ****
--- 779,785 ----

                      sequence = makeNode(CreateSeqStmt);
                      sequence->seqname = pstrdup(sname);
+                     sequence->istemp = stmt->istemp;
                      sequence->options = NIL;

                      elog(NOTICE, "CREATE TABLE will create implicit sequence '%s' for SERIAL column '%s.%s'",
***************
*** 2716,2722 ****
      return qry;
  }

! /*
   * Transform uses of %TYPE in a statement.
   */
  static Node *
--- 2717,2723 ----
      return qry;
  }

! /*
   * Transform uses of %TYPE in a statement.
   */
  static Node *
Index: src/backend/parser/gram.y
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/parser/gram.y,v
retrieving revision 2.231
diff -c -r2.231 gram.y
*** src/backend/parser/gram.y    2001/06/19 22:39:11    2.231
--- src/backend/parser/gram.y    2001/06/22 23:02:53
***************
*** 1574,1584 ****
   *
   *****************************************************************************/

! CreateSeqStmt:  CREATE SEQUENCE relation_name OptSeqList
                  {
                      CreateSeqStmt *n = makeNode(CreateSeqStmt);
!                     n->seqname = $3;
!                     n->options = $4;
                      $$ = (Node *)n;
                  }
          ;
--- 1574,1585 ----
   *
   *****************************************************************************/

! CreateSeqStmt:  CREATE OptTemp SEQUENCE relation_name OptSeqList
                  {
                      CreateSeqStmt *n = makeNode(CreateSeqStmt);
!                     n->istemp = $2;
!                     n->seqname = $4;
!                     n->options = $5;
                      $$ = (Node *)n;
                  }
          ;
Index: src/include/nodes/parsenodes.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/nodes/parsenodes.h,v
retrieving revision 1.132
diff -c -r1.132 parsenodes.h
*** src/include/nodes/parsenodes.h    2001/06/19 22:39:12    1.132
--- src/include/nodes/parsenodes.h    2001/06/22 23:02:55
***************
*** 402,407 ****
--- 402,408 ----
  {
      NodeTag        type;
      char       *seqname;        /* the relation to create */
+       bool        istemp;            /* is this a temp sequence? */
      List       *options;
  } CreateSeqStmt;

Index: src/interfaces/ecpg/preproc/preproc.y
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/interfaces/ecpg/preproc/preproc.y,v
retrieving revision 1.140
diff -c -r1.140 preproc.y
*** src/interfaces/ecpg/preproc/preproc.y    2001/06/13 12:38:58    1.140
--- src/interfaces/ecpg/preproc/preproc.y    2001/06/22 23:02:58
***************
*** 1289,1297 ****
   *
   *****************************************************************************/

! CreateSeqStmt:  CREATE SEQUENCE relation_name OptSeqList
                  {
!                     $$ = cat_str(3, make_str("create sequence"), $3, $4);
                  }
          ;

--- 1289,1297 ----
   *
   *****************************************************************************/

! CreateSeqStmt:  CREATE OptTemp SEQUENCE relation_name OptSeqList
                  {
!                     $$ = cat_str(4, make_str("create sequence"), $2, $4, $5);
                  }
          ;


В списке pgsql-patches по дате отправления:

Предыдущее
От: Jason Tishler
Дата:
Сообщение: Re: Python (PyGreSQL) make install patch
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Re: [GENERAL] [Help] Temporary Table: Implicitely created index not shown in \d i