squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

Inserting array value on postgresql

Open dennissetiawan opened this issue 1 year ago • 0 comments

I want to insert array to the table , the following code does not work.

	insertMap := map[string]interface{}{
		order_column_id:                 input.OrderID,
		order_column_assigned_users:     []string{userID},
	}

	query, args, err := sq.Insert(ORDER_TABLE).
		SetMap(insertMap).
		PlaceholderFormat(sq.Dollar).
		ToSql()

Please help me on:

  1. make the proper query to insert array
  2. i'm quite confused on how sq.Expr work , why does it does not work as expected?

EDIT:

insertMap := map[string]interface{}{
		order_column_id:                 input.OrderID,
		order_column_assigned_users:     sq.Expr("ARRAY[?]", userID),
	}

works but notice that if i use .Insert.Values(orderID , sq.Expr("ARRAY[?]",userID) ) It does not work.

dennissetiawan avatar Jul 13 '23 18:07 dennissetiawan