Know if a table exists or not in postgres

0

What happens is that I am trying to see if a table exists in postgres or not, I managed to make the query, the problem is that it is consulting if it exists in the whole postgres scheme and not in the base on which I am executing the query and it brings me more records since I have other databases that have tables with the same name. I would like you to help me to know what I need in the query. Thank you in advance.

SELECT table_name FROM information_schema.columns WHERE table_name='pais'
    
asked by Manuel Mosquera 30.07.2018 в 18:27
source

1 answer

0

You need to filter by table_schema for a specific schema, and table_catalog for a db

SELECT table_name FROM information_schema.columns 
WHERE table_name='pais' 
 AND table_catalog = 'TUDB'
 AND table_schema = 'TUSCHEMA'

For more information you should check this link, for the v PSQL V9.2

link

Greetings.

    
answered by 30.07.2018 / 18:32
source