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: f54607780705051431h1c0680a7y18a2ebc5f30a94f5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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
t_sites(IDSite,......,tName)

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

If , on PgAdmin, I query
SELECT IDSite
FROM t_sites
WHERE "tName"='www.record.pt\\\\'

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 = "www.record.pt\\\\"

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

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

i.e. the ExecuteScalar() Method returns one key, the www.record.pt\ one,
120120, but it should return null, because the result should be empty.
www.record.pt\ != www.record.pt\\ , 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
SELECT IDSite,tName
FROM t_sites
query against my postgres database and then lists the results on screen, and
the fact is that www.record.pt\\ does not appear which is correct.
Still, ExecuteScalar() behaves as the record was there and returns the
primary key of ...the www.record.pt\ 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,
Oliveiros

Lisboa,
Portugal

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

Responses

Browse pgsql-novice by date

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