When importing some data (10000) rows each time, I need to perform an INSERT or SELECT (insert if doesn’t exist or select if exist and return table_id) 7 times for each row.
At the moment I use the rails function, find_or_create_by
, this is usually working, but not for the value of rows I have, also it makes everything slower.
How can I create a function in postgres which will perform the insert or select and return the ids? Is it a good idea?