Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add schema to path in postgresql

I'm the process of moving applications over from all in the public schema to each having their own schema. for each application, I have a small script that will create the schema and then create the tables,functions,etc... to that schema. Is there anyway to automatically add a newly created schema to the search_path? Currently, the only way I see is to find the users current path SHOW search_path; and then add the new schema to it SET search_path to xxx,yyy,zzz;

I would like some way to just say, append schema zzz to the users_search path. is this possible?

like image 872
veilig Avatar asked Mar 25 '10 15:03

veilig


People also ask

What is schema search path PostgreSQL?

The default search path makes PostgreSQL search first in the schema named exactly as the user name you used for logging into the database. If the user name is different from the schema names, or there is no table szymon. a then it would look in the public.

How can I import the schema of a database in PostgreSQL?

The phpPgAdmin administration page appears in a new window. In the left pane of the phpPgAdmin window, expand Servers, expand PostgreSQL, and then click the name of the database that you want to import the data into. On the top menu bar, click SQL. The SQL link is located between the Schemas and Find links.


1 Answers

Use the set_config() function like so:

SELECT set_config(
    'search_path',
    current_setting('search_path') || ',zzz',
    false
) WHERE current_setting('search_path') !~ '(^|,)zzz(,|$)';
like image 66
theory Avatar answered Sep 28 '22 06:09

theory