@@ -81,23 +81,31 @@ private function cast(int $oid, ?string $value): array|bool|int|float|string|nul
8181
8282 $ type = $ this ->types [$ oid ] ?? PgSqlType::getDefaultType ();
8383
84- return match ($ type ->type ) {
85- 'A ' => ArrayParser::parse ( // Array
86- $ value ,
87- fn (string $ data ) => $ this ->cast ($ type ->element , $ data ),
88- $ type ->delimiter ,
89- ),
90- 'B ' => $ value === 't ' , // Boolean
91- 'N ' => match ($ oid ) { // Numeric
92- 700 , 701 => (float ) $ value , // "float4" and "float8" to float
93- 1700 => $ value , // Return "numeric" as string to retain precision
94- 790 => $ value , // "money" includes currency symbol as string
95- default => (int ) $ value , // All other numeric types cast to an integer
84+ return match ($ type ->category ) {
85+ 'A ' => match ($ type ->name ) { // Array
86+ 'int2vector ' , 'oidvector ' => $ value , // Deprecated array types
87+ default => ArrayParser::parse (
88+ $ value ,
89+ fn (string $ data ) => $ this ->cast ($ type ->element , $ data ),
90+ $ type ->delimiter ,
91+ ),
9692 },
97- default => match ($ oid ) { // String
98- 17 => \pg_unescape_bytea ($ value ),
99- default => $ value , // Return a string for all other types
93+ 'B ' => match ($ value ) {
94+ 't ' => true ,
95+ 'f ' => false ,
96+ default => throw new PostgresParseException ('Unexpected value for boolean field: ' . $ value ),
97+ }, // Boolean
98+ 'N ' => match ($ type ->name ) { // Numeric
99+ 'float4 ' , 'float8 ' => (float ) $ value ,
100+ 'int2 ' , 'int4 ' , 'oid ' => (int ) $ value ,
101+ 'int8 ' => \PHP_INT_SIZE >= 8 ? (int ) $ value : $ value , // String on 32-bit systems
102+ default => $ value , // Return a string for all other numeric types
100103 },
104+ 'U ' => match ($ type ->name ) {
105+ 'bytea ' => \pg_unescape_bytea ($ value ),
106+ default => $ value ,
107+ },
108+ default => $ value , // Return a string for all other types
101109 };
102110 }
103111}
0 commit comments