0

I have a PostgreSQL table that contains the following structure:

Parent     child1     child2
1          10         12
2          13         
3

I want to have:

 Parent     child1     child2
    1          10         12
    2          13         13
    3          3          3

I mean, if child2 is NULL, I want to duplicate child1 into child2; and if child1 is null, I want to duplicate the parent into child1 and child2.

1
  • 1
    COALESCE(child2,child1,parent) AS child2 Commented Sep 25, 2013 at 9:19

1 Answer 1

1

Do you mean something like:

select Parent,
       coalesce(child1, Parent) as child1,
       coalesce(child2, child1, Parent) as child2
from <tablename>;

?

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

1 Comment

Yeeees, it's exactly what i was looking fooor. Thank you so muchhh for your quick answers.

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.