Masterminds / squirrel

Fluent SQL generation for golang
Other
6.67k stars 458 forks source link

Inserting array value on postgresql #362

Open dennissetiawan opened 12 months ago

dennissetiawan commented 12 months ago

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.