Skip to content

Commit

Permalink
Added expicit array types, changed how they convert
Browse files Browse the repository at this point in the history
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
  • Loading branch information
chandr-andr committed Sep 29, 2024
1 parent 19d1746 commit f1cbe23
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,37 @@ async def main() -> None:
TextArray(["Foo", "Bar", "Cafe"]),
],
)
```
```

### Cannot insert empty ARRAY

To insert empty array use explicit [Array Type](./usage/types/array_types.md).

#### Problem and Solution:
Let's assume that we have table `arr_table` with field `some_array` of `VARCHAR ARRAY` type.
The main problem that we cannot determine the type of the empty sequence passed from Python side.
```python
from psqlpy import ConnectionPool
from psqlpy.extra_types import VarCharArray

# --- Incorrect ---
async def main() -> None:
pool = ConnectionPool()
await pool.execute(
querystring="INSERT INTO arr_table (some_array) VALUES ($1)",
parameters=[
[],
],
)


# --- Correct ---
async def main() -> None:
pool = ConnectionPool()
await pool.execute(
querystring="INSERT INTO arr_table (some_array) VALUES ($1)",
parameters=[
VarCharArray([]),
],
)
```

0 comments on commit f1cbe23

Please sign in to comment.