node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Passing in quoted tabled names for a create table query

Open DanielCoder834 opened this issue 1 year ago • 0 comments

I want to be able to create a tabled named "user" so I wrote this piece of code:

const client = await this.pool.connect();
sql= 'CREATE TABLE IF NOT EXISTS "user" (id UUID PRIMARY KEY DEFAULT gen_random_uuid())'; 
await client.query(sql); 

When I run the code, I get a parser error. If I run it with user without the quotation marks, I get an error for user is a special name for postgres. I have since found a round about solution to my initial problem which I was trying to use this library to solve.

Since I ran into this dilemma and I don't want other developers to fall into this pitfall, I think this would be the best place to bring it up. If you can't solve the issue, that's fine, but I thought it would be best for contributors and future developers to know about this issue. :)

DanielCoder834 avatar May 23 '24 22:05 DanielCoder834