Replies: 1 comment 2 replies
-
|
Hello! Yeah unfortunately Postgres doesn't expose enough information for squirrel to understand if those are nullable or not. There's a workaround though! You could pick a value to represent "null" and switch on that in your query: insert into products (id, legacy_id, name)
select
id,
+ nullif(legacy_id, -1),
name
from unnest($1::uuid[], $2::bigint[], $3::text[]) as t(id, legacy_id, name)In this case I'm assuming "-1" is not a valid legacy id, so it's ok to use that as representing "null". It's a workaround but works quite alright if you can pick one such value. Hope this helps! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying out squirrel on a new project and I was wondering, is there a good way to do bulk insert/upsert? I have a table that looks like this and am trying to figure out the best way to do this:
Let's say I have 100s of products I want to insert, and want to do it all in one query. Is there a recommended way to do this right now with squirrel?
One way that I tried is this:
This almost works. It generates a function with this signature:
Which, if you had a list of products, you could turn it into a list of each field value for each field in product.
However, for this to work I'd need the generated type of arg_2 to be
List(Option(Int)). Postgres arrays are allowed to have nulls in them, but squirrel mapsarray[T]toList(T). If there was some way to hint to squirrel that array elements can be null so it map toList(Option(T)), that would make this work. Alternatively, squirrel could map all array types toList(Option(T))which would be more correct, but also can be annoying sometimes.Does anyone have any ideas on how to make this work in the current version of squirrel? Otherwise for now I'll have to just use pog directly
Beta Was this translation helpful? Give feedback.
All reactions