Skip to content

Instantly share code, notes, and snippets.

@sebastianwebber
Created April 1, 2017 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianwebber/ef2ed025849cf0f4ef360f1adc8707a9 to your computer and use it in GitHub Desktop.
Save sebastianwebber/ef2ed025849cf0f4ef360f1adc8707a9 to your computer and use it in GitHub Desktop.
teste com o search_path
sebastian=# create schema esquema_a;
CREATE SCHEMA
sebastian=# create schema esquema_b;
CREATE SCHEMA
sebastian=# create schema esquema_c;
CREATE SCHEMA
sebastian=# create schema esquema_d;
CREATE SCHEMA
sebastian=# create schema esquema_e;
CREATE SCHEMA
sebastian=# create schema esquema_f;
CREATE SCHEMA
-- listo os esquemas que criei
sebastian=# \dn
List of schemas
Name | Owner
-----------+-----------
esquema_a | sebastian
esquema_b | sebastian
esquema_c | sebastian
esquema_d | sebastian
esquema_e | sebastian
esquema_f | sebastian
public | sebastian
(7 rows)
-- crio as tabelas necessarias
--- de proposito crio a mesma em cada banco
sebastian=# create table esquema_a.foo (id serial primary key, nome text);
CREATE TABLE
sebastian=# create table esquema_b.foo (id serial primary key, nome text);
CREATE TABLE
sebastian=# create table esquema_c.foo (id serial primary key, nome text);
CREATE TABLE
sebastian=# create table esquema_d.foo (id serial primary key, nome text);
CREATE TABLE
sebastian=# create table esquema_e.foo (id serial primary key, nome text);
CREATE TABLE
sebastian=# create table esquema_f.foo (id serial primary key, nome text);
CREATE TABLE
--- testo se as tabelas são listadas por padrão. (é esperado que não)
sebastian=# show search_path ;
search_path
-----------------
"$user", public
(1 row)
sebastian=# \d
No relations found.
--- faço uma query no `information_schema` pra validar se elas aparecem
------ propositalmente eu removo as tabelas do postgres e do próprio information_schema:
sebastian=# select table_schema, table_name from information_schema.tables where table_schema NOT LIKE 'pg_%' AND table_schema != 'information_schema';
table_schema | table_name
--------------+------------
esquema_a | foo
esquema_b | foo
esquema_c | foo
esquema_d | foo
esquema_e | foo
esquema_f | foo
(6 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment