Skip to content

Commit f1cbe23

Browse files
committed
Added expicit array types, changed how they convert
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent 19d1746 commit f1cbe23

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

docs/faq.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,37 @@ async def main() -> None:
9292
TextArray(["Foo", "Bar", "Cafe"]),
9393
],
9494
)
95-
```
95+
```
96+
97+
### Cannot insert empty ARRAY
98+
99+
To insert empty array use explicit [Array Type](./usage/types/array_types.md).
100+
101+
#### Problem and Solution:
102+
Let's assume that we have table `arr_table` with field `some_array` of `VARCHAR ARRAY` type.
103+
The main problem that we cannot determine the type of the empty sequence passed from Python side.
104+
```python
105+
from psqlpy import ConnectionPool
106+
from psqlpy.extra_types import VarCharArray
107+
108+
# --- Incorrect ---
109+
async def main() -> None:
110+
pool = ConnectionPool()
111+
await pool.execute(
112+
querystring="INSERT INTO arr_table (some_array) VALUES ($1)",
113+
parameters=[
114+
[],
115+
],
116+
)
117+
118+
119+
# --- Correct ---
120+
async def main() -> None:
121+
pool = ConnectionPool()
122+
await pool.execute(
123+
querystring="INSERT INTO arr_table (some_array) VALUES ($1)",
124+
parameters=[
125+
VarCharArray([]),
126+
],
127+
)
128+
```

0 commit comments

Comments
 (0)