-1

For some reason, I am facing this issue that in the existing database I have a user table where I have stored data manually, but when I am trying to access it through the query, I get this error.

ERROR: relation "user" does not exist

Can you kindly let me know what may cause this error? Just to mention here, I can access all the other tables present in the database.

  • 1
    Is that table in the public schema? check `show search_path;` for the user issuing that query or use fully qualified names (e.g. schema.table). – Pepe N O Jun 30 '23 at 21:29
  • Could you please share the ddl for this table and you query? We can now only guess what you try to do – Frank Heikens Jul 01 '23 at 04:36

9 Answers9

2

It's reserved word in PostgreSQL, so if you going to use a table named like that you need to wrap that name in double quotes.

Rabban Keyak
  • 220
  • 2
  • 6
0

Check if you're using the correct schema. For example, if the user table is in the public schema, you should use the query like:

SELECT * FROM public.user;

It's possible too that the table was not created or named correctly, or there may be an issue with the schema or permissions.

Wendel
  • 763
  • 1
  • 12
0

"user" is reserved key word in PostgreSQL, it refers current user or current role depending on the context.

to use user as table name you need to enclose it into quotation, "user"

see the following query for example:

SELECT * FROM "user";

0

users is a reserved keyword in postgreSQL and it is not a good practice to use reserved words for identifiers (tables or columns).

But if you need to use it you can wrap it with a double quotes like this “users”.

Another way to do this is to create table users in a schema other than public. Then you can use it as follows.

SELECT * FROM schema_name.users;
Omar Saad
  • 349
  • 3
  • 8
0

I have checked it from the postgresql official documentation that it is a reserved keyword and we cannot access it directly.

This keyword is reserved in all of these databases version:

Key Word    PostgreSQL  SQL:2016    SQL:2011    SQL-92
USER        reserved    reserved    reserved    reserved

From here you can check that it cannot be accessed directly. The best way to get that table information is mentioned below:

Select * from "USER";

If you are using any other keyword that is reserved too, then you have to follow the same procedure too. You can check the reserved keywords list from the following link.

Documentation Link

0

As everyone has mentioned, "user" is a reserved keyword so good practice is to avoid making use of it.

However, there could be a chance that you're not using it properly. Enclosing it in "" helps it to be used.

Similarly, do make sure that there is a "user" clause in your tables. Overall, you could redesign your tables to not use the user word.

Shanzay
  • 19
  • 3
0

a lot of the Programming languages has reserved words and the PostgreSQL as well.

Verify those words before try to use them as name of variables, you can check to PG reserved words by this following link: Reserved Words in PostgreSQL

Marcos Silva
  • 115
  • 5
0

As others have already suggested USER is a reserved keyword in Postgres. You might want to have a look at the this link which shows the all reserved words: reserved-words

You can see that even a word like CURRENT_USER is reserved so its best to avoid these. I say avoid because you can still have a table named as a reserved word by using double quotes. You can see some examples above. Its highly recommended to avoid this practice though.

0

As mentioned by other users, the keyword "users" is a reserved keyword in PostgreSQL and based on the context, it can be used for the default user. Thus it is not recommended and is not good practice to be using reserved words as identifiers.