Skip site navigation (1) Skip section navigation (2)

PL/SQL dynamic update error

From: "Eduardo Ferreira" <eduardo(dot)edusantos(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: PL/SQL dynamic update error
Date: 2007-07-25 18:46:05
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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
    ||' 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'
    EXECUTE v_command;


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

Next:From: Steve HoldowayDate: 2007-07-25 20:53:25
Subject: Re: Using Explain
Previous:From: Tom LaneDate: 2007-07-25 17:34:12
Subject: Re: Localisation

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group