pg_copy_from() not working
Posted: Tue Jul 06, 2010 10:09 am
Hi All
I have an ODBC and a postgres database with identical schemas. I am trying to write a simple program that reads data from an ODBC table and inserts the values into a Postgres table. I have tested the tables by using an ETL tool that does a straight copy from the ODBC table to to the Postgres table, which works perfectly.
Here is my code:
<?php
$odbc_conn=odbc_connect("odbc_db", "Administrator", "password");
$pg_conn=pg_connect('host=localhost dbname=pg_db user=postgres password=postgres');
$sql="SELECT * FROM Customers";
$a=odbc_exec($odbc_conn, $sql);
$b = odbc_fetch_into($a, $rows);
pg_copy_from($pg_conn, "Customers", $rows);
odbc_close($odbc_conn);
pg_close($pg_conn);
?>
I keep getting an error - Warning: pg_copy_from(): Copy command failed: ERROR: missing data for column "Col1".
This is the first column in the table and a print_r of the $rows variable shows the correct values have been fetched from the ODBC database. Even though this is only a warning, no data gets loaded into the postgres database.
I have tried to manually create an array rather than fetching the data from the ODBC source, just to see if I can get the pg_copy_from() to work but also no luck.
Please help
Thanks
O
I have an ODBC and a postgres database with identical schemas. I am trying to write a simple program that reads data from an ODBC table and inserts the values into a Postgres table. I have tested the tables by using an ETL tool that does a straight copy from the ODBC table to to the Postgres table, which works perfectly.
Here is my code:
<?php
$odbc_conn=odbc_connect("odbc_db", "Administrator", "password");
$pg_conn=pg_connect('host=localhost dbname=pg_db user=postgres password=postgres');
$sql="SELECT * FROM Customers";
$a=odbc_exec($odbc_conn, $sql);
$b = odbc_fetch_into($a, $rows);
pg_copy_from($pg_conn, "Customers", $rows);
odbc_close($odbc_conn);
pg_close($pg_conn);
?>
I keep getting an error - Warning: pg_copy_from(): Copy command failed: ERROR: missing data for column "Col1".
This is the first column in the table and a print_r of the $rows variable shows the correct values have been fetched from the ODBC database. Even though this is only a warning, no data gets loaded into the postgres database.
I have tried to manually create an array rather than fetching the data from the ODBC source, just to see if I can get the pg_copy_from() to work but also no luck.
Please help
Thanks
O