100Starlings / redshift_ecto

Redshift adapter for Ecto
https://hexdocs.pm/redshift_ecto/
Other
14 stars 11 forks source link

RETURNING is not supported by Redshift #1

Closed phereford closed 6 years ago

phereford commented 6 years ago

Hi there! Thank you for your work on this gem.

I am experiencing an issue. Here is my stack trace:

** (EXIT) an exception was raised:                                                                                                         
        ** (ArgumentError) RETURNING is not supported by Redshift                                                                              
            (redshift_ecto) lib/redshift_ecto/connection.ex:988: RedshiftEcto.Connection.error!/2                                              
            (redshift_ecto) lib/redshift_ecto.ex:98: RedshiftEcto.insert/6                                                                     
            (ecto) lib/ecto/repo/schema.ex:547: Ecto.Repo.Schema.apply/4                                                                       
            (ecto) lib/ecto/repo/schema.ex:213: anonymous fn/14 in Ecto.Repo.Schema.do_insert/4 

Here is the code I am using to invoke it:

alias MyApp.Repo
alias MyApp.Store.MyAppSchema

%MyAppSchema{}
    |> MyAppSchema.changeset(data)
    |> Repo.insert([])

What am I doing wrong here? Any advice is appreciated. Thanks!

phereford commented 6 years ago

I figured it out! Ecto has on by default read_after_writes: true option for the primary key of an Ecto.Schema.

This removed that error:

@primary_key {:id, :integer, read_after_writes: false}
lackac commented 6 years ago

@phereford Good to know, I wasn't familiar with that option.

In general you want to generate ids on the client side with Redshift because of the lack of RETURNING support which Ecto adds to queries implicitly if the id would be generated by the db.