I have a large database, that I want to do some logic to update new fields.
The primary key is "id" for the table harvard_assignees
The LOGIC GOES LIKE THIS
- Select all of the records based on "id"
- For each record (WHILE), if (state is NOT NULL && country is NULL), update country_out = "US" ELSE update country_out=country
I see step 1 as a PostgreSQL query and step 2 as a function. Just trying to figure out the easiest way to implement natively with the exact syntax.
==== The second function is a little more interesting, requiring (I believe) DISTINCT:
- Find all DISTINCT foreign_keys (a bivariate key of pat_type,patent)
- Count Records that contain that value (e.g., n=3 records have fkey "D","388585")
- Update those 3 records to identify percent as 1/n (e.g., UPDATE 3 records, set percent = 1/3)
Thanks in advance!
monte
{x: