Skip site navigation (1) Skip section navigation (2)

Re: Importing a CSV file to a table on Postgres

From: "Oliveiros Cristina" <oliveiros(dot)cristina(at)gmail(dot)com>
To: phillip(dot)smith(at)weatherbeeta(dot)com(dot)au
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Importing a CSV file to a table on Postgres
Date: 2007-05-05 21:31:45
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Hello, Phillip.
Hello, all.

Thank you for your email, it worked nicely.

Now I have another question not related to this one, and I am not sure if
this is the right list or if there is a specialized list.
It has to do with Npgsql, the C# interface to postgres.

I have a table that looks like the following

Suppose I have a row on this table e.g.
120120 .......\

If , on PgAdmin, I query
FROM t_sites
WHERE "tName"='\\\\'

I get nothing, as expected, because the string has two final backslashes,
not one, as the record on table.

But if I try to do it on C# it returns me the 120120. (??) It shouldn't
return nothing as well.
The program is as follows :

strSite = "\\\\"

strQuery = "SELECT \"IDSite\" FROM t_sites " + "WHERE \"tName\" = '" +
strSite + "'";

cSqlCommand = new NpgsqlCommand(strQuery, m_cConnectionToDb);
    i_int_rec.IDSite = (int)cSqlCommand.ExecuteScalar();
/* This code is not executed */

i.e. the ExecuteScalar() Method returns one key, the\ one,
120120, but it should return null, because the result should be empty.\ !=\\  , is that not true?
Does the ExecuteScalar() method remove additional backslashes or kinda?

Actually I did on C# a small test program that issues the
FROM t_sites
query against my postgres database and then lists the results on screen, and
the fact is that\\ does not appear which is correct.
Still, ExecuteScalar() behaves as the record was there and returns the
primary key of ...the\ which is not the right one!

Can anyone please kindly indicate what am I doing wrong on the program?

Any help/advice deeply appreciated

Warm Regards,


2007/5/4, Phillip Smith <phillip(dot)smith(at)weatherbeeta(dot)com(dot)au>:
>  I'm not familiar with PGAdmin, but with console you can use a way likethis to insert the contents of a CSV-file into a database table on aremote host:
> cat <file.csv> | ssh <host> "psql -U <user> <database> -c 'copy <table> from stdin;'"
> You can do the same from pgAdmin, you just need to upload the file to the
> server first, then do something like:
>     COPY table1 FROM '/tmp/file1.txt';
> Remember to write the path as the SERVER will see it, not as the client
> sees it!
> ********************Confidentiality and Privilege
> Notice********************
> The material contained in this message is privileged and confidential to
> the addressee. If you are not the addressee indicated in this message or
> responsible for delivery of the message to such person, you may not copy or
> deliver this message to anyone, and you should destroy it and kindly notify
> the sender by reply email.
> Information in this message that does not relate to the official business
> of Weatherbeeta must be treated as neither given nor endorsed by
> Weatherbeeta. Weatherbeeta, its employees, contractors or associates shall
> not be liable for direct, indirect or consequential loss arising from
> transmission of this message or any attachments

In response to


pgsql-novice by date

Next:From: Tom LaneDate: 2007-05-06 00:34:42
Subject: Re: Importing a CSV file to a table on Postgres
Previous:From: Tom LaneDate: 2007-05-04 14:37:29
Subject: Re: Trigger and Notify

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group