Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting array value on postgresql #362

Open
dennissetiawan opened this issue Jul 13, 2023 · 0 comments
Open

Inserting array value on postgresql #362

dennissetiawan opened this issue Jul 13, 2023 · 0 comments

Comments

@dennissetiawan
Copy link

dennissetiawan commented Jul 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant