Skip to main content

Array Types

...

For type safety and better performance we have predefined array types.

PSQLPy Array TypePostgreSQL Array Type
BoolArrayBOOLEAN ARRAY
UUIDArrayUUID ARRAY
VarCharArrayVarChar ARRAY
TextArrayText ARRAY
Int16ArrayINT2 ARRAY
Int32ArrayINT4 ARRAY
Int64ArrayINT8 ARRAY
Float32ArrayFLOAT4 ARRAY
Float64ArrayFLOAT8 ARRAY
MoneyArrayMONEY ARRAY
IpAddressArrayINET ARRAY
JSONBArrayJSONB ARRAY
JSONArrayJSON ARRAY
DateArrayDATE ARRAY
TimeArrayTIME ARRAY
DateTimeArrayTIMESTAMP ARRAY
DateTimeTZArrayTIMESTAMPTZ ARRAY
MacAddr6ArrayMACADDR ARRAY
MacAddr8ArrayMACADDR8 ARRAY
NumericArrayNUMERIC ARRAY
PointArrayPOINT ARRAY
BoxArrayBOX ARRAY
PathArrayPATH ARRAY
LineArrayLINE ARRAY
LsegArrayLSEG ARRAY
CircleArrayCIRCLE ARRAY
IntervalArrayINTERVAL ARRAY

Example:

from psqlpy import ConnectionPool
from psqlpy.extra_types import TextArray


async def main() -> None:
    pool = ConnectionPool()
    result = await pool.execute(
        querystring="SELECT * FROM users WHERE name = ANY($1)",
        parameters=[
            TextArray(["Alex", "Dev", "Who"]),
        ]
    )