How to copy values from a table into another table during PostgreSQL EF migration?

31 views Asked by At

I use ASP.NET, PostgreSQL and Entity Framework.

I have to copy current values of the sequences I use into a new table.

Creating new table during migration is obvious. Then I can acquire all sequence names like follows: SELECT "sequence_name" FROM "information_schema"."sequences";. Then for each one I can find its current value like follows: SELECT currval('<sequence_name>');.

But I can't receive any data from SELECT during Up method of the EF migration.

What approach should I do? I mean how to retrieve data that I can then INSERT?

Just one strategy I can figure out is to add a procedure that would then be EXEC during this migration. But this seem to be not efficient since I need to call this query just once per history of the product.

Then the other question is how to compose SELECT from "information_schema"."sequences" with the currval for each row? I know about CURSOR. May someone suggest better way?

0

There are 0 answers