0

I have created a Table as follows

CREATE TABLE parentChild
(
  id serial NOT NULL,
  parentID integer,
  childIds integer[],
  CONSTRAINT PARENTCHILD_pkey PRIMARY KEY (id)
)

I have also Inserted several elements in this table

Initial Table View

id | ParentID | ChildIDs
------------------------
1  | 0        | 
2  | 0        | 

When I insert Child of "1" where child ID will be 3 and its parent ID will be 1, I wish to append 3 to the Child IDs integer array at id=1 as shown below.

id | ParentID | ChildIDs
------------------------
1  | 0        | 3,4
2  | 0        |
3  | 1        | 

Could you please let me know how to achieve this?

1 Answer 1

1

Here you can find array operators: http://www.postgresql.org/docs/9.1/static/functions-array.html

You can try this query:

Update parentChild
Set childid = childid || 3
Where id = 1
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.