Re: error: insert has more expressions than target column

From: Dino Vliet <dino_vliet(at)yahoo(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: error: insert has more expressions than target column
Date: 2004-09-07 14:54:49
Message-ID: 20040907145449.26038.qmail@web40105.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

MUCH better now....I did manage to get an insert into
the table lessons with these adjustments...BUT now it
seems the FOR LOOP didn't work because I only get 1
record and expected that I would get 8 records due to
the i variabele.

What could be wrong?

My code is now:

CREATE FUNCTION vulalles() RETURNS trigger AS '
BEGIN
FOR i in 0..7 LOOP
INSERT INTO lessons (......)
SELECT dayofweek,startdate + (i*7), enddate +
(i*7),...;
RETURN NEW;
END LOOP;
END;
' LANGUAGE plpgsql;

--- Richard Huxton <dev(at)archonet(dot)com> wrote:

> Dino Vliet wrote:
> > I'm getting the same error without brackets.
>
> Check the columns in table "lessons" matches the
> columns in your select.
>
> > The EXECUTE statement was because I read something
> > about executing dynamic content.
> >
> > I want to add 7 days to the date value of
> startdate
> > and want to repeat it every week. Because there
> are 8
> > weeks I choose to do that with the for loop going
> from
> > 0 to 7.
>
> Looking closer, I can see the problem. You're
> treating the column from
> the select as a variable (which it isn't).
>
> Try something like:
>
> INSERT INTO lessons (col_name1, col_name2, ...)
> SELECT dayofweek, startdate + (i*7), endate + (i*7),
> startime, ...
>
> --
> Richard Huxton
> Archonet Ltd
>


__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mário Gamito 2004-09-07 14:58:22 Problems importing data from plain text file
Previous Message Tom Lane 2004-09-07 14:54:38 Re: ERROR: canceling query due to user request