@@ -461,7 +461,21 @@ def _system_timezone():
461461 0 ,
462462 10 ,
463463 4294967295
464- ])
464+ ]),
465+ ('oid8' , 'oid8' , (
466+ 0 ,
467+ 1 ,
468+ 2 ** 32 ,
469+ 2 ** 63 ,
470+ 2 ** 64 - 1 ,
471+ ), (19 , 0 )),
472+ ('regdatabase' , 'regdatabase' , (
473+ 'postgres' ,
474+ 'template0' ,
475+ 'template1' ,
476+ '-' ,
477+ '4294967295' ,
478+ ), (19 , 0 )),
465479]
466480
467481
@@ -552,6 +566,38 @@ async def test_all_builtin_types_handled(self):
552566 codec ,
553567 'core type {} ({}) is unhandled' .format (typename , oid ))
554568
569+ async def test_oid8 (self ):
570+ if self .server_version < (19 , 0 ):
571+ self .skipTest ('oid8 requires PostgreSQL 19 or later' )
572+
573+ values = [0 , 2 ** 32 , 2 ** 63 , 2 ** 64 - 1 , None ]
574+ result = await self .con .fetchval ('SELECT $1::oid8[]' , values )
575+ self .assertEqual (result , values )
576+
577+ for value in (- 1 , 2 ** 64 , 2 ** 256 ):
578+ with self .subTest (value = value ):
579+ with self .assertRaisesRegex (
580+ asyncpg .DataError , 'value out of uint64 range' ):
581+ await self .con .fetchval ('SELECT $1::oid8' , value )
582+
583+ # A text fallback would accept this; the integer codec must reject it.
584+ with self .assertRaises (asyncpg .DataError ):
585+ await self .con .fetchval ('SELECT $1::oid8' , '42' )
586+
587+ async def test_regdatabase (self ):
588+ if self .server_version < (19 , 0 ):
589+ self .skipTest ('regdatabase requires PostgreSQL 19 or later' )
590+
591+ oid = await self .con .fetchval (
592+ "SELECT oid FROM pg_database WHERE datname = 'postgres'" )
593+ result = await self .con .fetchval ('SELECT $1::regdatabase' , str (oid ))
594+ self .assertEqual (result , 'postgres' )
595+
596+ result = await self .con .fetchval (
597+ "SELECT current_database()::regdatabase" )
598+ self .assertEqual (result , await self .con .fetchval (
599+ 'SELECT current_database()' ))
600+
555601 async def test_void (self ):
556602 res = await self .con .fetchval ('select pg_sleep(0)' )
557603 self .assertIsNone (res )
0 commit comments