From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
---|---|
To: | Wilfred Benson <hairymcfarsen(at)hotmail(dot)com>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Subquery in INSERT? |
Date: | 2006-10-17 15:34:45 |
Message-ID: | 20061017153445.67236.qmail@web31813.mail.mud.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
> What I'm trying to do is copy a value from one column to another in the same
> table. The table looks like this:
>
> first | second
> ---------------------
> 1 |
> 2 |
> 3 |
> 4 |
> ...
>
> It's named 'copier'.
>
> The first column is sequence-generated, and the second has yet to have
> anything loaded (at this stage it's only a test table). So what I'm trying
> to do is quick copy of '1' from 'first' to 'second' with this query:
>
> INSERT INTO copier VALUES(nextval('sequence'), ((SELECT first FROM copier
> WHERE copier.first=1) AS second));
>
> ...and I'm getting this error:
> ERROR: syntax error at or near "AS" at character 93
>
> So what I want to know is, is it possible? If it is and my query is
> incorrect and anyone can tell me what's wrong with it that would be great.
INSERT adds new rows to a table. It will not copy a value from one column to another. The UPDATE
statement can do this however.
UPDATE table set second = first;
Regards,
Richard Broersma Jr.
From | Date | Subject | |
---|---|---|---|
Next Message | me | 2006-10-17 16:28:25 | Re: bad planner pick... but why? |
Previous Message | Sean Davis | 2006-10-17 13:59:39 | Re: could not write to hash-join temporary file: No space left on device |