ndrean
I am using a CSV dataset in SQLite to seed. It seems that I can insert data but I can’t read it ! Something obvious must be missing but I just don’t see.
The table looks like this:
def create_table(conn, table) do
Exqlite.Sqlite3.execute(
conn,
"CREATE TABLE IF NOT EXISTS #{table} (
id integer primary key,
ident string,
elevation_ft string,
type string,
name string,...
I also have a schema and a Repo.
defmodule Airport do
use Ecto.Schema
import Ecto.Changeset
@headers headers
@columns Enum.map(@headers, &String.to_atom/1)
schema "csv" do
Enum.each(@columns, &field(&1, :string))
#timestamps()
end
def changeset(attrs \\ %{}) do
%Airport{}
|> cast(attrs, @columns)
|> validate_required(@columns -- [:iata_code])
end
end
I check that the fields are :ok
Airport.__schema__(:fields)
[:id, :ident, :type, :name, :elevation_ft...]
Now it seems that I can insert (?) a row:
l = %{
coordinates: "-74.93360137939453, 40.07080078125",
elevation_ft: "11",
gps_code: "00A",
...
}
|> Airport.changeset()
|> Repo.insert()
which returns:
[debug] QUERY OK db=0.9ms idle=1248.3ms
INSERT INTO "csv" (coordinates","elevation_ft","gps_code....
{:ok,
%Airport{
__meta__: #Ecto.Schema.Metadata<:loaded, "csv">,
id: 57424,
ident: "00A",....
but I can’t read it !??
Repo.get(Airport, 1)
** (ArgumentError) cannot load `11` as type :string for field :elevation_ft in %Airport{__meta__:
It seems that I can insert my whole file, but I can’t read it either:
Repo.aggregate(Airport, :count)
57342
Seems good, but:
Repo.all(Airport)
** (ArgumentError) cannot load `11` as type :string for field :elevation_ft in
%Airport{__meta__: #Ecto.Schema.Metadata<:loaded, "csv">, id: nil, ident: nil, type: nil, name: nil, elevation_ft: nil,
...
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #elixirconf-us
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mindok
Have you tried updating your Ecto schema field type for
:elevation_ft? It looks like it is failing when trying to coerce an integer from SQLite into a string in Elixir.Edit: check your CSV - I can’t tell from the sample error whether :elevation_ft is integer or float.
Edit2: From what I understand, SQLite is pretty slack about field types - they are advisory only. From my reading of it, you need to be pretty disciplined to ensure your Ecto schema definition matches what’s actually in the table. When I’ve used SQLite in Elixir I’ve bypassed Ecto and put some bespoke type-casting code in place as I had no idea what would be coming in, but it somehow had to end up a number for some charts.
ndrean
ok, I knew it was something stupid. The correct type is TEXT, not “STRING” with SQLite. I wasn’t running a migration, I was creating the table via SQL! What is misleading is that errors are inserted as “nil” values.