-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
TypeORM VirtualColumn cause error in table creation and querying #390
Comments
are you been able to fix this ? |
No I have not, I suspect this is related to the parser of pg-mem, and I've give up using virtual column, instead I'll just use a raw query and select whatever calculated column I need, then write code to fill the calculated result into a non-column field in the entity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Use VirtualColumn feature in TypeORM (https://orkhan.gitbook.io/typeorm/docs/decorator-reference#virtualcolumn) cause issues with table creation, table would either fail to create the table and later on run into
relation "Foo" does not exist
error, or the table could be mis-structured and run intocolumn "Foo.bar" does not exist
, even thoughbar
is defined in the entity.Removing the field annotated with
@VirtualColumn
would allow pg-mem to behave correctly.To Reproduce
The generated SQL from TypeORM by calling
dataSource.getRepository(TestEntity).find()
looks like below:With the entity defined above, the SQL generated above would fail with error
relation "TestEntity" does not exist
. However, if simply remove the@VirtualColumn
fieldtest_sum
, the.find()
call would succeed without any problem. It also would not work if we copy the generated SQL and calldataSource.getRepository(TestEntity).query(sql)
, the failure is the same.If we change the query in virtual column to use direct table name instead of alias:
SELECT SUM(num) FROM "test"
, the query would run without error, but the returned result only contains result of the subquery for virtual column, theid
andnum
fields are missing in the returned object.We have verified the query can run successfully in an actual Postgres v16 DB.
pg-mem version
2.8.1
The text was updated successfully, but these errors were encountered: