github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/pgwire/testdata/pgtest/enum (about)

     1  # This test verifies some of the pgwire encoding process for ENUMs.
     2  
     3  # Prepare the environment.
     4  send noncrdb_only
     5  Query {"String": "DROP TYPE IF EXISTS te"}
     6  ----
     7  
     8  until noncrdb_only ignore=NoticeResponse
     9  ReadyForQuery
    10  ----
    11  {"Type":"CommandComplete","CommandTag":"DROP TYPE"}
    12  {"Type":"ReadyForQuery","TxStatus":"I"}
    13  
    14  send crdb_only
    15  Query {"String": "SET experimental_enable_enums=true;"}
    16  ----
    17  
    18  until crdb_only
    19  ReadyForQuery
    20  ----
    21  {"Type":"CommandComplete","CommandTag":"SET"}
    22  {"Type":"ReadyForQuery","TxStatus":"I"}
    23  
    24  send
    25  Query {"String": "CREATE TYPE te AS ENUM ('hi', 'hello')"}
    26  ----
    27  
    28  until
    29  ReadyForQuery
    30  ----
    31  {"Type":"CommandComplete","CommandTag":"CREATE TYPE"}
    32  {"Type":"ReadyForQuery","TxStatus":"I"}
    33  
    34  # Use the enum now.
    35  send
    36  Query {"String": "SELECT 'hi'::te"}
    37  ----
    38  
    39  # PostgreSQL uses float4 under the hood.
    40  until ignore_type_oids noncrdb_only
    41  RowDescription
    42  ----
    43  {"Type":"RowDescription","Fields":[{"Name":"te","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":0,"DataTypeSize":4,"TypeModifier":-1,"Format":0}]}
    44  
    45  # Note that this is slightly different than Postgres -- in Postgres the
    46  # DataTypeSize for an enum is 4, as floats are used to represent enums
    47  # internally (4 bytes). Since our encodings are variable size, we report
    48  # the DataTypeSize to be -1, which is the variable length size.
    49  until ignore_type_oids crdb_only
    50  RowDescription
    51  ----
    52  {"Type":"RowDescription","Fields":[{"Name":"te","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":0,"DataTypeSize":-1,"TypeModifier":-1,"Format":0}]}
    53  
    54  until
    55  ReadyForQuery
    56  ----
    57  {"Type":"DataRow","Values":[{"text":"hi"}]}
    58  {"Type":"CommandComplete","CommandTag":"SELECT 1"}
    59  {"Type":"ReadyForQuery","TxStatus":"I"}