# This test verifies that the DataTypeSize field in the RowDescription and
# DataRow messages both agree when using the MAX aggregate on an INT4 column.

# Prepare the environment.
send
Query {"String": "DROP TABLE IF EXISTS minmax_test"}
----

until ignore=NoticeResponse
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"DROP TABLE"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send
Query {"String": "CREATE TABLE minmax_test (id INT8 PRIMARY KEY, b INT4, c FLOAT4)"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"CREATE TABLE"}
{"Type":"ReadyForQuery","TxStatus":"I"}


send
Query {"String": "INSERT INTO minmax_test (id, b, c) VALUES (1, 1000, 11.1), (2, 250, 55.5)"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"INSERT 0 2"}
{"Type":"ReadyForQuery","TxStatus":"I"}

send
Query {"String": "SELECT max(b), min(c) FROM minmax_test"}
----

until
ReadyForQuery
----
{"Type":"RowDescription","Fields":[{"Name":"max","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"min","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":700,"DataTypeSize":4,"TypeModifier":-1,"Format":0}]}
{"Type":"DataRow","Values":[{"text":"1000"},{"text":"11.1"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# 'P' for Portal
send
Parse {"Name": "s1", "Query": "SELECT max(b), min(c) FROM minmax_test"}
Bind {"DestinationPortal": "p1", "PreparedStatement": "s1"}
Describe {"ObjectType": "P", "Name": "p1"}
Execute {"Portal": "p1"}
Sync
----

until ignore_table_oids
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"RowDescription","Fields":[{"Name":"max","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"min","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":700,"DataTypeSize":4,"TypeModifier":-1,"Format":0}]}
{"Type":"DataRow","Values":[{"text":"1000"},{"text":"11.1"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}

# 'P' for Portal
# ResultFormatCodes [1] = FormatBinary
send
Parse {"Name": "s2", "Query": "SELECT max(b), min(c) FROM minmax_test"}
Bind {"DestinationPortal": "p2", "PreparedStatement": "s2", "ResultFormatCodes": [1,1]}
Describe {"ObjectType": "P", "Name": "p2"}
Execute {"Portal": "p2"}
Sync
----

until ignore_table_oids
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"RowDescription","Fields":[{"Name":"max","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":1},{"Name":"min","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":700,"DataTypeSize":4,"TypeModifier":-1,"Format":1}]}
{"Type":"DataRow","Values":[{"binary":"000003e8"},{"text":"A1\ufffd\ufffd"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"I"}
