Reputation: 2578
After various Google searches, I am still scratching my head with the problem of selecting a table that is not under the default public schema in PostgreSQL.
I did however, try to reference the Postgres' schema in the model definition, but with no luck, and looking at the logs, I see why as it is queried "quoted"
schema "nonpublicschema.sometable" do
field :somefield, :string
end
Throws:
ERROR | relation "nonpublicschema.sometable" does not exist
ERROR | SELECT u0."somefield" FROM "nonpublicschema.sometable" AS u0
I do understand that is not a bug, but I would like to know how else I can achieve this.
Upvotes: 3
Views: 528
Reputation: 51429
Unfortunately we don't support the approach you have defined. Please open up an issue and we can improve it.
Meanwhile, there are some work arounds. You will need Ecto 1.0.2 for this. For the query, you can set a prefix:
query = from p in Model, ...
query = %{query | prefix: "nonpublicschema"}
For models, you need to do:
model = Ecto.Model.put_meta model, prefix: "nonpublicschema"
Alternatively, you can define a after_connect(conn, opts)
callback in your repository, and use the Postgrex API to automatically expand your search path.
Upvotes: 3