Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load into case sensitive tables #476

Closed
jiripsota opened this issue Nov 10, 2016 · 7 comments
Closed

Cannot load into case sensitive tables #476

jiripsota opened this issue Nov 10, 2016 · 7 comments

Comments

@jiripsota
Copy link

jiripsota commented Nov 10, 2016

Trying to load using configuration file like...

LOAD CSV
        FROM 'Articles.txt'
                HAVING FIELDS
                (
                        art_no, name
                )
        INTO postgres://xxx?RawArticles

It doesn't work with case-sensitivity. RawArticles is automatically converted to rawarticles.
Loader throws

 fatal: pgloader found 0 target tables for name "rawarticles"|:

Any suggestions?
Thanks :)

@dimitri
Copy link
Owner

dimitri commented Nov 13, 2016

You should be able to quote the table name to enforce its spelling, so please try the following:

INTO postgres://xxx?"RawArticles"

@dimitri
Copy link
Owner

dimitri commented Nov 13, 2016

Seems it needed the "quote identifier" option to be available, which is now possible. Please try with it, as shown in the merged patch test case that has been updated to benefit from the feature.

@jiripsota
Copy link
Author

jiripsota commented Nov 14, 2016

Thanks for quick fix. I tried last version, but it unfortunately not working:

my configuration:

postgres://xxx?"RawArticles"

and it throws error

ERROR Database error 42P01: relation "rawarticlesales" does not exist

And other problem is, that in bigger projects you are working also with schemes (or just not working in public scheme), so it should work like postgres://xxx?scheme_name."RawArticles".

@dimitri
Copy link
Owner

dimitri commented Nov 14, 2016

You need to add the WITH option quote identifiers as in the provided example for your quoting to work. The notation you're proposing for the schema qualified table names happens to be the one that works already!

See the provided example at 526fafb#diff-1e709cdccf39fc2f633922224fac6688

@CakozorusRex
Copy link

CakozorusRex commented Jan 4, 2017

Hello Dimitri.
I'm not quite sure this issue is entirely resolved.
Let me explain my case.

I have a table named 'TABLE' in the schema 'schema'. The table has only one row named 'ATT1'.
By reading about this issue, I understand that I have to protect both my table name and my column name with double quotes to avoid the lower case enforcement (and also add the 'quote identifiers' option).

My configuration file looks like this :

LOAD CSV
    FROM '../../../test.csv'
    HAVING FIELDS
    (
        ATT1
    )
INTO postgresql://cako:pwd@127.0.0.1/postgres?tablename=schema."TABLE"
    TARGET COLUMNS
    (
        "ATT1"
    )
WITH skip header = 0,
     fields escaped by double-quote,
     fields terminated by ';',
     quote identifiers;

This doesn't work and returns the following error :
FATAL pgloader found 0 target tables for name "\"schema\".\"TABLE\""|:

But if I replace the above 'connection string' by :
INTO postgresql://cako:pwd@127.0.0.1/postgres?tablename="TABLE"
and creates the table 'TABLE' into the public schema, it works.

So it seems that adding the schema name as a prefix to the table name breaks the 'quote identifiers' feature. I tried simple and double quotes, quoting the schema, etc. I could never get it to work.

Am I missing something?
You should also note that while in the given use case the schema name is in lower case and thus doesn't need to be 'protected', it will not always be the case and IMO we should also be able to protect the schema name. As a consequence, this should also work :
INTO postgresql://cako:pwd@127.0.0.1/postgres?tablename="SCHEMA"."TABLE"

Sorry if this is not clear, english is not my primary language...

Thanks,
CakozorusRex.

dimitri added a commit that referenced this issue Jan 10, 2017
See #476 where it would have been helpful to see the PostgreSQL catalog
queries with `--log-min-messages sql` in the bug report. Also more
generally useful.
dimitri added a commit that referenced this issue Jan 10, 2017
Avoid double quoting the schema names when used in PostgreSQL catalog
queries, where the identifiers are used as literal values and need to be
single-quoted.

Fix #476, again.
@dimitri
Copy link
Owner

dimitri commented Jan 10, 2017

It should be good now, please build and test again.

@CakozorusRex
Copy link

Hello Dimitri,
Sorry for the late reply.

I can confirm that it now works for my use case.

Thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants