14

Postgresql version: 9.1.9

I'm trying to insert data into a table using SELECT and passing values

Example of what i try to accomplish:

current database:

MyTable
character    number
'a'            '0'
'b'            '1'
'c'            '1'

what i want:

MyTable
character    number
'a'            '0'
'b'            '1'
'c'            '1'
'b'            '2'
'c'            '2'

I tried different things but i can't seem to get it right. For example:

INSERT INTO MyTable (character, number)
    (SELECT character FROM MyTable WHERE number = '1', '2')

Note: The numbers are actually long strings and therefore have to be in brackets.

Thanks.

1 Answer 1

23
INSERT INTO MyTable (character, number) 
    SELECT character, '2' FROM MyTable WHERE number = '1'

to save the data in the same format on your example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.