ijdickinson

ijdickinson

Reference data table in PostgreSQL schema

I have a collection of (basically static) reference data for my app, which is loaded separately into a Postgres schema reference_data. I want to query data from tables in that schema in my app’s Ecto queries. My first attempt was:

from parcel in "reference_data.living_england_habitat_map_phase_4",
    select: [parcel.ogc_fid],
    where: ...

When I run this query, I get an error:

[error] GenServer #PID<0.872.0> terminating
** (Postgrex.Error) ERROR 42P01 (undefined_table) relation "reference_data.living_england_habitat_map_phase_4" does not exist

    query: SELECT r0."ogc_fid", r0."id", r0."a_pred", r0."b_pred", r0."geom" FROM "reference_data.living_england_habitat_map_phase_4" AS r0 WHERE ...  LIMIT 10

The table does exist in that database, and I can query it from psql. If I swap the table reference to be a table in the public schema, I don’t get this error. So, if I’m understanding this correctly, I can’t access my reference_data schema table using:

from: parcel in "reference_data.living_england_habitat_map_phase_4",

because that generates as SQL

SELECT r0."ogc_fid" FROM "reference_data.living_england_habitat_map_phase_4"

instead of FROM reference_data.living_england_habitat_map_phase_4 without double-quotes.

What should I be doing instead?

Marked As Solved

al2o3cr

al2o3cr

The @schema_prefix option sounds like what you’re looking for.

Also Liked

hauleth

hauleth

It is possible:

Repo.all(query, prefix: "reference_data")

Last Post!

ijdickinson

ijdickinson

Ah, thanks @hauleth!

Where Next?

Popular in Questions Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement