-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non PK UUID column and returning
#757
Comments
I'm not sure I understand. ActiveRecord doesn't have an
Can you show the values for |
Pardon, coffee has not kicked in. I agree Active Record does not have an import method so that was my bad. The method I was trying to use instead of creating an object normally was What I wanted was to do in Ruby what I'd do with a SQL statement where I specified It matches up pretty close to here: https://dev.to/jbranchaud/a-few-methods-for-returning-default-values-when-creating-activerecord-objects-1457 I think activerecord-import might be better than using a manual SQL insert statement here. But I'm looking at the SQL that is generated and it does look like NULL is being set on the VALUES portion of the insert statement. Since our column allows null maybe this is why? I changed the model to "Foo" below and removed extraneous stuff. This be like:
Here is a SQL statement I'd run manually where I'm not specifying the external_id column at all. This is the non-PK UUID column that gets a default UUID value:
So maybe I'm just doing this wrong but for a column that has a generated UUID value, should I be able to use Many thanks! |
Our use case here is that we're inserting into a partitioned table that is heavily written to, and the immediate lookup afterwards to fetch the value because normal Active Record |
Ohh I understand now, so To work around that you could try using an array or arrays or array of hashes to control which columns get included in the insert SQL. |
Thank you for taking a look and thinking on this @jkowens - as a workaround for now I'm setting the UUID in code instead of the DB. But I'll give what you're saying a shot. Your explanation that the instances are already created in a list and have null/nil values makes sense. |
Possibly fixed by this #802 |
Hello. I wanted to take advantage of
RETURNING
to save a round-trip to the database for an area that is particularly costly. However activerecord-import which we're using (just bumped to latest) in the Rails app (Rails 5.x) seems to take over theimport
method that Active Record provides that would let me specify areturning
clause which I initially intended to use, then stumbled into activerecord-import.Is there a way around activerecord-import definition of
import
of I want to try the Active Record one? Am I missing something on that?The other problem is that I see activerecord-import supports
returning
but I'm only seeing examples with a primary key in past issues for the project. We're using the uuid-oosp extension to generate a UUID. Are non-PK columns supported or different in some way? We have this UUID generation happening as the column default. When I insert one record and query it again I see it there in the DB. I see use activerecord-import to insert a single record in a list, it says it is inserted but the in-memory instance does not have the value set, it's not in the returning results, and if I query again I see the column appears null.e.g. Successful insert of single row where we have
external_id
as a UUID non-PK column. But the results are a single nil item and I expected it to be the value forexternal_id
.The text was updated successfully, but these errors were encountered: