1

I would like to use array variable in PostgreSQL array_append(). If I use array directly then its works but not when using variable.

  $name= {1,2,3};
  $Name_key_array={4};

I would like to find result by using following way-

  $name='array_append(name, $Name_key_array)';

or

  "SELECT array_append($Books->name, $Name_key_array) as b";

Waiting to see some great ideas.

Thanks to all

1
  • it's a wild guess as I can't test it, just try $name = "[1,2,3]" and $Name_key_array = "[4]", or $name = "ARRAY[1,2,3]" the idea here is that the array declaration should be in postgresql not php, as for postgresql to understand it. give it a try withing this concept and let me know. Commented Dec 7, 2013 at 5:40

1 Answer 1

1

personally, I use json.

<?php $json_var = json_encode($array) 
$sql="insert into blah (arr) values (select array_agg(a::text) from json_array_elements(:json_var)";

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.