question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Column doesn't exist when creating table

See original GitHub issue

Basic info

pg-mem version: 1.9.9 jest version: 27.0.4 typeorm version: 0.2.35

Reproduction link: https://gist.github.com/Sven65/5b462e2d2d4ded3d8f89d4792bf4fd6b

Issue

When trying to create a table using pg-mem and typeorm entities, it fails as the column doesn’t exist, with the following error message:

QueryFailedError: column "userid" does not exist

    🐜 This seems to be an execution error, which means that your request syntax seems okay,
    but the resulting statement cannot be executed → Probably not a pg-mem error.

    *️⃣ Failed SQL statement: CREATE TABLE "userStats" ("userID" character varying(255) NOT NULL, CONSTRAINT "UQ_abb77da609fd701b7052a8b4531" UNIQUE ("userID"), CONSTRAINT "PK_abb77da609fd701b7052a8b4531" PRIMARY KEY ("userID"));

Stacktrace

 at QueryFailedError.TypeORMError [as constructor] (src/error/TypeORMError.ts:7:9)
      at new QueryFailedError (src/error/QueryFailedError.ts:9:9)
      at PostgresQueryRunner.call (src/driver/postgres/PostgresQueryRunner.ts:258:19)
      at step (node_modules/typeorm/node_modules/tslib/tslib.js:143:27)
      at Object.throw (node_modules/typeorm/node_modules/tslib/tslib.js:124:57)
      at rejected (node_modules/typeorm/node_modules/tslib/tslib.js:115:51)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
oguimbalcommented, Sep 1, 2021

Hi ! I just fixed it.

I still have several (unrelated) unit tests to fix, but it will be published with the next pg-mem version, hopefully a bit later this week.

Thanks for the feedback 😃

2reactions
linsolascommented, Sep 1, 2021

More of my investigation. The problem is not on pg-mem but more on pgsql-ast-parser. When it parses the constraints, it transforms the column name in lowercase.

If I take the SQL code generated by the @Sven65 code, and I put it on the pg-mem playground, we can see that it fails saying that column userid does not exist:

CREATE TABLE "userStats" (
    "userID" character varying(255) NOT NULL,
    CONSTRAINT "UQ_abb77da609fd701b7052a8b4531" UNIQUE ("userID"),
    CONSTRAINT "PK_abb77da609fd701b7052a8b4531" PRIMARY KEY ("userID")
);

image

But with everything in lowercase, it works:

CREATE TABLE "userStats" (
    "userid" character varying(255) NOT NULL,
    CONSTRAINT "UQ_abb77da609fd701b7052a8b4531" UNIQUE ("userid"),
    CONSTRAINT "PK_abb77da609fd701b7052a8b4531" PRIMARY KEY ("userid")
);

image

I will create a ticket on pgsql-ast-parser repository…

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostgreSQL "Column does not exist" but it actually does
This problem occurs in postgres because the table name is not tablename instead it is "tablename". for eg. If it shows user as...
Read more >
PostgreSQL column does not exist | Definition and Syntax
The column does not exist exception occurs in PostgreSQL when we have not used a specified column name while doing any operations. Also,...
Read more >
How to Fix Column Does not Exist Exception/Error in ...
In PostgreSQL, the “column doesn't exist” error can occur because of various reasons, such as the searched column doesn't exist in the targeted ......
Read more >
Troubleshooting - Column does not exist - Workato Docs
UndefinedColumn - Column Does Not Exist is a type of SQL statement error. It indicates that the database cannot find the specified column....
Read more >
ERROR: column “…” does not exist - Pinter Computing
The first line of the error message shows, that PostgreSQL internally converted UserName to username. To be able to reference the column, use ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found