From: Eduardo Ferreira <eduardo.edusantos@gmail.com>
To: pgsql-admin@postgresql.org
Subject: PL/SQL dynamic update error
Date: Wed, 25 Jul 2007 15:46:05 -0300
Message-ID: <266b12630707251146q8c96d4an125d6835f0a236d0@mail.gmail.com> (raw)
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?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: eduardo.edusantos@gmail.com
Subject: Re: PL/SQL dynamic update error
In-Reply-To: <266b12630707251146q8c96d4an125d6835f0a236d0@mail.gmail.com>
References: <266b12630707251146q8c96d4an125d6835f0a236d0@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox