On Friday, October 5, 2018 at 3:17:04 PM UTC-7, Mike Pastore wrote:
>
> Hi Jeremy, 
>
> I have a Postgres table with two identity columns: the primary key (:id) 
> and another column (:order_number). I want to create a Sequel::Model 
> instance, save it to this table, and have it take the next values in each 
> of the two sequences. However, Sequel is trying to insert a NULL into the 
> :order_number column, which is invalid (identity columns are NOT NULL). If 
> I do :identity=>:always in my migration, the INSERT INTO still includes the 
> NULL and fails, but the error includes the note about OVERRIDING SYSTEM 
> VALUE. 
>
> How can I tell Sequel not to include the :order_number column in the 
> INSERT INTO statement if it's nil? (Should the Postgres adapter exclude all 
> identity columns by default unless given a non-nil value?) Alternatively, 
> is there some sentinel value I can assign to the :order_number field that 
> will get passed to Postgres and coax it to do the right thing? 
>
> I'm hoping this is just a simple case of the Friday night stupids and your 
> answer will immediately enlighten me, as it usually does. Thanks in advance.
>

I've no doubt that what you are describing is happening, but a simple 
example does not reproduce:

 
DB.create_table(:bs) do
  primary_key :id
  Integer :order_number, :identity=>true
  Integer :n
end

class B < Sequel::Model; end

B.create(:n=>1)
# INSERT INTO "bs" ("n") VALUES (1) RETURNING *


Can you modify this simple example to get the same failure you are seeing 
so I can debug?

If you just want to work around it:

B.create(:n=>1, :order_number=>Sequel.lit('DEFAULT'))
# INSERT INTO "bs" ("n", "order_number") VALUES (1, DEFAULT) RETURNING *

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to