I know I can insert an array into a Postgres database with pg_query.
INSERT into table (field) VALUES ('{{element, element},{}}')
But how about using pg_insert?
$array["field"] = "{{element, element},{}}";
$result = pg_insert($con, "table", $array);
Will the string {{element, element},{}} be actually inserted into field as a 2D Postgres array?
I’ve always wanted to test that out but currently I don’t have any PostgreSQL DB to test with..
I just ran your specific example.
(1) in Postgres:
(2) in PHP:
And I got the following error:
I tried playing around with the array value: make it 2×2 array, one-dimensional, etc., etc. – the same result. I even changed the table to have the field as one-dimensional array:
text[]and changed the code accordingly – and I still get the same result.I started digging further and found the following on PHP documentation for
pg_insert:Basically, it’s pretty buggy and shouldn’t be used. Interestingly, using
works just fine. Hopefully, this answers your question. 🙂