Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not handle array types #86

Open
SamGrisey opened this issue Sep 21, 2024 · 4 comments · Fixed by #87
Open

does not handle array types #86

SamGrisey opened this issue Sep 21, 2024 · 4 comments · Fixed by #87

Comments

@SamGrisey
Copy link

SamGrisey commented Sep 21, 2024

It would seem that array types are not being recognized properly. If I create a simple table:

CREATE TABLE IF NOT EXISTS test (
    id serial NOT NULL PRIMARY KEY,
    tags TEXT[]
);

then add some rows and do a

res = await transaction.fetch("SELECT * FROM test;")
return res.result()

the return res.result() line causes a crash:

pyo3_runtime.PanicException: called `Option::unwrap()` on a `None` value

The rust code looks like its expecting a postgres type "TEXT ARRAY" but the type is really "text[]". Even if I declare the table column as having type "TEXT ARRAY" instead of "TEXT[]", \d still reports it as "text[]"

EDIT:
It actually works fine with the same simple table on a fresh database, there must be something different with the existing database... but the array column does indeed crash with that error with fetched on the old database, just no idea why now...

@chandr-andr
Copy link
Member

@SamGrisey Hello!
Thank you very much for the issue.
I’ll look into it today.

@SamGrisey SamGrisey reopened this Sep 21, 2024
@SamGrisey
Copy link
Author

SamGrisey commented Sep 21, 2024

Ignore what I said above, the error seems to be with empty array values, not my old db instance.
Example SQL:

CREATE TABLE IF NOT EXISTS test (
    id serial NOT NULL PRIMARY KEY,
    locked_fields text[] NOT NULL DEFAULT array[]::text[]
);

INSERT INTO test VALUES(1, '{"abc"}');
INSERT INTO test(id) VALUES(2);
INSERT INTO test VALUES(3, ARRAY[]::TEXT[]);

SELECTING all within psql terminal yields:

SELECT * FROM test;
 id | locked_fields 
----+---------------
  1 | {abc}
  2 | {}
  3 | {}
(3 rows)

so as you can see, all rows have arrays (neither are NULL), yet id 2 was auto-populated by its default value and 3 was explicitly set empty.

now on psqlpy, running SELECT * FROM test WHERE id = 1; works fine, but running SELECT * FROM test WHERE id = 2; and SELECT * FROM test WHERE id = 3; will cause that crash.

@chandr-andr
Copy link
Member

@SamGrisey Okay, I know what’s the problem here, I’ll fix it as soon as I come to my laptop

@chandr-andr chandr-andr linked a pull request Sep 21, 2024 that will close this issue
@chandr-andr chandr-andr reopened this Sep 21, 2024
@chandr-andr
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants