0

I have extracted list of names of tables in database using this sql query:

"SELECT table_name from information_schema.tables"

I got this list:

    table_name
1   main_table
2   kp_table
3   ids_table
4   main_logs

Then i want to extract table ids_table:

"SELECT * from ids_table"

So desired result is to get that table, but i get this error:

Error: Failed to prepare query: ERROR:  relation "ids_table" does not exist
LINE 1: SELECT * from ids_table

Why it happens? Why i get from first query its name, but then it tells me that it doesn't exist?

8
  • Check schema like dbo.Ids_table (is default) other schema need wirte after table name Commented Jun 19, 2020 at 11:58
  • 1
    Can you add the schema name to the query from information_schema? Commented Jun 19, 2020 at 11:58
  • @Mureinik i don't know it Commented Jun 19, 2020 at 12:00
  • Have you tried adding the schema_name in front of the table name like SELECT * FROM schema.ids_table Commented Jun 19, 2020 at 12:00
  • 1
    If you don't know the schema you can display it using select table_schema, table_name from information_schema.tables Commented Jun 19, 2020 at 12:01

2 Answers 2

2

In this case, I would say that the most common issue is that you are looking at two different databases. That is probably not the cause in this case.

Another common possibility is that the schema is something unexpected, and you should be referencing the schema. For that, include the schema in the query:

select table_schema, table_name
from information_schema.tables

Another possibility are hidden characters, such as spaces. You can see if this is the problem by adding delimiters so check the names:

select '|' || table_name || '|'
from information_schema.tables
Sign up to request clarification or add additional context in comments.

1 Comment

yeah it was schema reference problem
0

It looks like you are trying to select data from different schema, which by default owns by different user, but you have access to it. As this table is not created by user, which you are using for select * from ... , you must indicate schemas name before table name. Without schemas name it's trying to select date from users schema, but actually table are owned by completely different user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.