PL/SQL dynamic update error - Mailing list pgsql-admin

From Eduardo Ferreira
Subject PL/SQL dynamic update error
Date
Msg-id 266b12630707251146q8c96d4an125d6835f0a236d0@mail.gmail.com
Whole thread Raw
List pgsql-admin
I have a table with informations that change every month, and I have to update the monthly data in a new column. To do that, I try to find out wich months are being trated and I perform an update in my table for every month.

So what I'm trying to do is to change the month column for a fixed name, perform my selects and updates in the renamed column and change the name back for its old value. Then I do exactly the same thing for another month. It would be something like this:

FOR month IN select month from monht_values LOOP
    v_command: = 'ALTER TABLE my_table
    RENAME COLUMN m'
    ||month
    ||' TO month_value;';

    EXECUTE v_command;

    UPDATE my_table
    SET month_value = new_value
    WHERE key = my_key;

    v_command: = 'ALTER TABLE my_table
    RENAME COLUMN month_value TO m'
    ||month
    ||';';
    EXECUTE v_command;

END LOOP;


The query works just fine, but the updates are made allways in the same column. Even when I change the name, PostgreSQL doesn't recognize it, and all the updates are performed in the same first column name. It seems like it stores the column information in a way I can't change the it.

Any ideas on how to fix it?

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: Localisation
Next
From: "Sorin N. Ciolofan"
Date:
Subject: granting acces to an external client