Home > Mobile >  Postgres get current schema name
Postgres get current schema name

Time:11-05

I want to get my current connection schema name I found that 'show search_path' returns the needed result but I need to use this result in the query.

How can I use "show search_path" in a Postgres query?

if not (SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE 
  table_name = 'customer' and table_schema = **show search_path** )) then
do something ....
end

I need to use table_schema = show search_path

CodePudding user response:

SELECT EXISTS (
  SELECT 1 FROM information_schema.tables
  WHERE table_name = 'project_customer_scheme'
  AND table_schema = (
    SELECT setting FROM pg_settings WHERE name = 'search_path'
)

CodePudding user response:

Use the current_schema function. It gives you the first schema on the search_path that actually exists, that is, the schema where unqualified tables will be created.

  • Related