0

Hi I'm connecting to postgres database and transfer data to my local machine.

here is my code :

        public DataTable GetDataTable(string sql)
    {
        var conn = GetOpenConnection();
        var dt = new DataTable();

        var cmd = conn.CreateCommand();
        cmd.CommandText = sql;

        NpgsqlDataReader dr = null;

        try
        {
            dr = cmd.ExecuteReader();
            dt.Load(dr);
        }
        catch (Exception ex)
        {
            Log.Info(ex);
            throw;
        }
        finally
        {
            dr.Close();
            conn.Close();
        }

        return dt;
    }

Below scenarios working fine

sql = "SELECT * FROM test_db"

sql= "SELECT * FROM testdb"

But if; sql = "SELECT * FROM testDb" then I got exception

Error 42P01 "testdb" does not exist

I notice that several tables. If I used camelcase data tables name every time it throws an exception. Here is the code which I got my exception

dr = cmd.ExecuteReader();

So I would like to know can't I call camelCase tables? What is the best solution fro this ?

appreciate your feedback and answers !! Thank you

Gayan
  • 1,425
  • 4
  • 21
  • 41
  • But your tables are written in lowercase or do you have them in mixed case? I could be wrong but this seems to be more a case sensitivity of PostGre that doesn't allow mixed case names and wants the table name to be exactly in the same case. – Steve Dec 01 '14 at 17:17
  • 1
    @Steve: The SQL standard specifies that unquoted identifiers are folded to upper case, PostgreSQL folds them to lower case. This difference rarely matters as they both normalize the case of unquoted identifiers. If you need case sensitive identifiers then SQL says that you need to double quote them. Some databases use backticks for quoting identifiers, some use brackets, but the PostgreSQL and standard SQL use double quotes. – mu is too short Dec 01 '14 at 18:01
  • This duplicates lots of questions (search for "[postgresql] case sensitive identifier" and you'll find some of them). – mu is too short Dec 01 '14 at 18:04
  • @Steve: Can I get resource link to prove this ? – Gayan Dec 01 '14 at 18:38
  • In the duplicate provided there are links to the official docs. – Steve Dec 01 '14 at 18:44

0 Answers0