Home > Archive > PHP with PostgreSQL > June 2005 > pg_put_line() Frustration









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author pg_put_line() Frustration
Simon Hewitt

2005-06-20, 9:23 am

Hi all,

I am currently working on an application that will input multple lines into
a Postgre database. I am using the following code

$sql = "COPY table_2 FROM STDIN DELIMITER AS '\t'";
pg_query($dbc, $sql);
$sql = $data1."\t".$data2."\t".implode("\t",
$data)."\ttrue\t05-05-2005\n";
pg_put_line($this->dbc, $sql);
if(!pg_put_line($dbc
, "\\N"))
{
pg_end_copy($dbc);
$error_message('Coul
d not enter details');
}
else
{
pg_end_copy($this->dbc);
unset($data);
}

This gives me an example line like

57 BELF 254 0 10877
5138 0 0 true 05-05-2005

To go into a table with fields INT, CHAR(4) INT, INT, INT, INT, INT, INT,
BOOL, DATE

However, its not going in...

I'm getting an error

ERROR: missing data for column "col2"

With no data being inserted.

If anyone could point out where I'm going wrong I'd be forever in their debt

Thanks

Simon



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Michael Fuhr

2005-06-20, 9:24 am

On Mon, Jun 20, 2005 at 01:29:47PM +0000, Simon Hewitt wrote:
>
> I am currently working on an application that will input multple lines into
> a Postgre database. I am using the following code


It's PostgreSQL or Postgres, not Postgre.

> $sql = "COPY table_2 FROM STDIN DELIMITER AS '\t'";
> pg_query($dbc, $sql);
> $sql = $data1."\t".$data2."\t".implode("\t",
> $data)."\ttrue\t05-05-2005\n";
> pg_put_line($this->dbc, $sql);
> if(!pg_put_line($dbc
, "\\N"))


The last line above attempts to add a row with a single NULL value,
so you get an error about missing data for the other columns. What's
the purpose of that line? Why do you sometimes use $dbc and sometimes
$this->dbc? Do they refer to the same connection or to different
connections?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Christopher Kings-Lynne

2005-06-20, 9:24 am

Use pg_copy_to and pg_copy_from instead...

Chris

Simon Hewitt wrote:
> Hi all,
>
> I am currently working on an application that will input multple lines
> into a Postgre database. I am using the following code
>
> $sql = "COPY table_2 FROM STDIN DELIMITER AS '\t'";
> pg_query($dbc, $sql);
> $sql = $data1."\t".$data2."\t".implode("\t",
> $data)."\ttrue\t05-05-2005\n";
> pg_put_line($this->dbc, $sql);
> if(!pg_put_line($dbc
, "\\N"))
> {
> pg_end_copy($dbc);
> $error_message('Coul
d not enter details');
> }
> else
> {
> pg_end_copy($this->dbc);
> unset($data);
> }
>
> This gives me an example line like
>
> 57 BELF 254 0 10877 5138 0 0 true 05-05-2005
>
> To go into a table with fields INT, CHAR(4) INT, INT, INT, INT, INT,
> INT, BOOL, DATE
>
> However, its not going in...
>
> I'm getting an error
>
> ERROR: missing data for column "col2"
>
> With no data being inserted.
>
> If anyone could point out where I'm going wrong I'd be forever in their
> debt
>
> Thanks
>
> Simon
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com