mmmrrr
I need to include multiple legacy migrations (written in plain SQL) in an ecto migration.
The current legacy application relies heavily on custom ENUM types in postgresql.
When I try to run the existing migrations (concatenated as a string) via execute my_combined_sql I will get the error cannot insert multiple commands into a prepared statement.
The minimal example of a failing SQL file is:
CREATE TYPE UState AS ENUM ("state1", "state2");
CREATE TABLE IF NOT EXISTS Users
(userEmail VARCHAR(320) NOT NULL PRIMARY KEY,
state UState NOT NULL);
Is there a way to do this with ecto, or do I need another process to apply the legacy migrations to the database?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kip
By default Ecto uses prepared statements (this is like a precompiled form of the statement which is the cached so that reuse is materially faster).
There is an option
prepare: :unnamedwhich I think goes on the Repo configuration (its a Postgrex adapter option) but I can’t recall and I’m in China this week so googling isn’t an option.Sorry its an incomplete answer but hopefully thats enough to get you started…
kip
On reflection, I suspect this won’t go either because the statements are still prepared and, as the message says, you can’t have more than one.
Indeed I recall having to split SQL statements at the
;in one use case and passing them one-by-one.This is primarily a
Postegrexissue, notEcto.mmmrrr
Hey @kip
Thanks for the input and taking the time.
In principle this shouldn’t be a problem to execute the statements one by one. This specific migration does not need to execute fast.
Just to clearify: I could split my SQL statements into a list and then call
execute SUBQUERY1,execute SUBQUERY2, etc. in the sameup/downstatement, right?This sounds a lot like “macro” to me
kip
Now I’ve paid a little more attention… I believe the issue is that you can’t create the
Enumin the same transaction as using it.Typically what I do in this case is actually prepare two migrations: one to create the
Enumand the other to create the table.However should be perfectly ok to:
mmmrrr
Awesome!
Thanks for the feedback. I will try that
mmmrrr
Great! That worked. It needed a little cleanup in the sql files in order to work, but it does now.
For anyone interested: If you have a List/Array of sql statements, you can use a simple macro like:
in your up migration:
NobbZ
Why a macro at all? If you had written it as a function, then there would be no noeed to quote and unquote…
Or even simpler, have it inline:
mmmrrr
Hm. Good point.
I somehow assumed the execute statement would not allow to be called at runtime… now that I think of it, it’s probably stupid
Thanks for the input