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

     1  # This test verifies that we're sending the right OIDs for different integer sizes.
     2  # The output can be a little hard to read but the important part is the DataTypeOIDs.
     3  # OID 20 is INT8, OID 23 is INT4.
     4  
     5  # Clean up the environment.
     6  send
     7  Query {"String": "DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t2"}
     8  ----
     9  
    10  until ignore=NoticeResponse
    11  ReadyForQuery
    12  ----
    13  {"Type":"CommandComplete","CommandTag":"DROP TABLE"}
    14  {"Type":"CommandComplete","CommandTag":"DROP TABLE"}
    15  {"Type":"ReadyForQuery","TxStatus":"I"}
    16  
    17  # Start of test.
    18  
    19  
    20  # By default, int == int8.
    21  send crdb_only
    22  Query {"String": "SELECT 1::int, 2::int4, 3::int8"}
    23  ----
    24  
    25  until crdb_only
    26  ReadyForQuery
    27  ----
    28  {"Type":"RowDescription","Fields":[{"Name":"int8","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0},{"Name":"int4","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"int8","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0}]}
    29  {"Type":"DataRow","Values":[{"text":"1"},{"text":"2"},{"text":"3"}]}
    30  {"Type":"CommandComplete","CommandTag":"SELECT 1"}
    31  {"Type":"ReadyForQuery","TxStatus":"I"}
    32  
    33  # Same results when selecting from a table.
    34  send crdb_only
    35  Query {"String": "CREATE TABLE t1 (a int, b int4, c int8)"}
    36  ----
    37  
    38  until crdb_only
    39  ReadyForQuery
    40  ----
    41  {"Type":"CommandComplete","CommandTag":"CREATE TABLE"}
    42  {"Type":"ReadyForQuery","TxStatus":"I"}
    43  
    44  send crdb_only
    45  Query {"String": "SELECT * FROM t1"}
    46  ----
    47  
    48  until crdb_only
    49  ReadyForQuery
    50  ----
    51  {"Type":"RowDescription","Fields":[{"Name":"a","TableOID":52,"TableAttributeNumber":1,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0},{"Name":"b","TableOID":52,"TableAttributeNumber":2,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"c","TableOID":52,"TableAttributeNumber":3,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0}]}
    52  {"Type":"CommandComplete","CommandTag":"SELECT 0"}
    53  {"Type":"ReadyForQuery","TxStatus":"I"}
    54  
    55  # Now change the default_int_size setting.
    56  send crdb_only
    57  Query {"String": "SET default_int_size=4"}
    58  ----
    59  
    60  until crdb_only
    61  ReadyForQuery
    62  ----
    63  {"Type":"CommandComplete","CommandTag":"SET"}
    64  {"Type":"ReadyForQuery","TxStatus":"I"}
    65  
    66  # The setting doesn't affect explicit casts, only table definitions.
    67  # (So in CockroachdB ::int is still ::int8, whereas it's ::int4 in postgres.)
    68  send crdb_only
    69  Query {"String": "SELECT 1::int, 2::int4, 3::int8"}
    70  ----
    71  
    72  until crdb_only
    73  ReadyForQuery
    74  ----
    75  {"Type":"RowDescription","Fields":[{"Name":"int8","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0},{"Name":"int4","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"int8","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0}]}
    76  {"Type":"DataRow","Values":[{"text":"1"},{"text":"2"},{"text":"3"}]}
    77  {"Type":"CommandComplete","CommandTag":"SELECT 1"}
    78  {"Type":"ReadyForQuery","TxStatus":"I"}
    79  
    80  ## Everything after this point should be the same between CockroachDB
    81  ## and PostgreSQL.
    82  
    83  
    84  # Create a new table with the new setting.
    85  send
    86  Query {"String": "CREATE TABLE t2 (a integer, b int4, c int8)"}
    87  ----
    88  
    89  until
    90  ReadyForQuery
    91  ----
    92  {"Type":"CommandComplete","CommandTag":"CREATE TABLE"}
    93  {"Type":"ReadyForQuery","TxStatus":"I"}
    94  
    95  # The int column is now an int4.
    96  send
    97  Query {"String": "SELECT * FROM t2"}
    98  ----
    99  
   100  until ignore_table_oids
   101  ReadyForQuery
   102  ----
   103  {"Type":"RowDescription","Fields":[{"Name":"a","TableOID":0,"TableAttributeNumber":1,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"b","TableOID":0,"TableAttributeNumber":2,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"c","TableOID":0,"TableAttributeNumber":3,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0}]}
   104  {"Type":"CommandComplete","CommandTag":"SELECT 0"}
   105  {"Type":"ReadyForQuery","TxStatus":"I"}
   106  
   107  # t1 is unchanged. It was created under the old configuration so its int column is int8.
   108  send crdb_only
   109  Query {"String": "SELECT * FROM t1"}
   110  ----
   111  
   112  until crdb_only
   113  ReadyForQuery
   114  ----
   115  {"Type":"RowDescription","Fields":[{"Name":"a","TableOID":52,"TableAttributeNumber":1,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0},{"Name":"b","TableOID":52,"TableAttributeNumber":2,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"c","TableOID":52,"TableAttributeNumber":3,"DataTypeOID":20,"DataTypeSize":8,"TypeModifier":-1,"Format":0}]}
   116  {"Type":"CommandComplete","CommandTag":"SELECT 0"}
   117  {"Type":"ReadyForQuery","TxStatus":"I"}