lkananowicz
Is there a way to use custom/varying column names in fragment? I mean the situation where I have 2 almost similar tables coming from different databases. Only couple of columns are different for historical reasons and I use those column names inside fragment(s). I want to unify Ecto queries to both of those tables as they were executed separately before.
Using simple questionmark notation fragment("?", column_name) causes column name to be appended into fragment however column ends up wrapped into double-quotes which is not desired.
Here is an example:
{:ok, datetime} = DateEx.convert_date_to_datetime(date)
CheapestConnection
|> where([cc], cc.kind == "round_trip_recent")
|> order_by([cc], fragment("abs(date_part('day', departure_date - ?)), price", type(^datetime, :utc_datetime)))
|> CheapestConnectionsRepo.all()
The column I would like to choose depending on certain conditions (like DB/Repo is used) is departure_date. That column name is different in another database. As a side note this query basically orders records by closest date relative to datetime.
Trending in Questions
Other Trending Topics
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 4 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
lkananowicz
@fuelen Thanks a lot! Yes, that solves the problem.
fuelen
You can solve this by defining the same field with different sources in schemas
lkananowicz
@kip Thanks for the suggestion, actually I am looking for something like:
As I mentioned before
custom_column_namewill be wrapped into double-quotes which is not desired.kip
Would:
work?