[
https://issues.apache.org/jira/browse/IGNITE-16322?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17479339#comment-17479339
]
Andrey N. Gura edited comment on IGNITE-16322 at 1/20/22, 12:51 PM:
--------------------------------------------------------------------
Just an example of how it works in PostgeSQL:
PostgreSQL converts identifiers to lower case by default.
```
create table tbl (
id int primary key
);
select * from tbl; // ok
select * from TBL; // ok
select * from tBl; // ok
select * from "tbl"; // ok
select * from "TBL"; // fail
// fail
create table "tbl" (
id int primary key
);
// CREATE ONE MORE TABLE
create table "TBL" (
id2 int primary key
); // ok
select * from tbl; // ok (id)
select * from TBL; // ok (id)
select * from tBl; // ok (id)
select * from "tbl"; // ok (id)
select * from "TBL"; // ok (id2)
------------------------------------------
// Example with filed name clashed names
create table tbl2 (
id int primary key,
user_name varchar,
"USER_NAME" varchar
)
select * from tbl2;
---------------------------
id | user_name | USER_NAME|
---------------------------
// And, of course, there is corner cases which should be taken into account
WARNING: It is possible to use quotes in identifier name
create table """tbl""" (
id int primary key
) // ok, table name will "tbl" (name includes
double quotes)
```
was (Author: agura):
Just an example of how it works in PostgeSQL:
PostgreSQL converts швутешашукы to lower case by default.
```
create table tbl (
id int primary key
);
select * from tbl; // ok
select * from TBL; // ok
select * from tBl; // ok
select * from "tbl"; // ok
select * from "TBL"; // fail
// fail
create table "tbl" (
id int primary key
);
// CREATE ONE MORE TABLE
create table "TBL" (
id2 int primary key
); // ok
select * from tbl; // ok (id)
select * from TBL; // ok (id)
select * from tBl; // ok (id)
select * from "tbl"; // ok (id)
select * from "TBL"; // ok (id2)
------------------------------------------
// Example with filed name clashed names
create table tbl2 (
id int primary key,
user_name varchar,
"USER_NAME" varchar
)
select * from tbl2;
---------------------------
id | user_name | USER_NAME|
---------------------------
// And, of course, there is corner cases which should be taken into account
WARNING: It is possible to use quotes in identifier name
create table """tbl""" (
id int primary key
) // ok, table name will "tbl" (name includes
double quotes)
```
> Database object names case inconsisten between SQL and KV API
> -------------------------------------------------------------
>
> Key: IGNITE-16322
> URL: https://issues.apache.org/jira/browse/IGNITE-16322
> Project: Ignite
> Issue Type: Bug
> Components: sql
> Affects Versions: 3.0.0-alpha3
> Reporter: Taras Ledkov
> Assignee: Taras Ledkov
> Priority: Major
> Labels: ignite-3
> Fix For: 3.0.0-alpha5
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Examples fail with NPE because table with the specified name does not exist.
> The actual table name is PUBLIC.ACCOUNTS (all uppercase), same for column
> names - ACCOUNTNUMBER and so on.
> *Current behavior*
> {{CREATE TABLE mytable(id INT, val INT)}}; -> creates PUBLIC.MYTABLE (ID, VAL)
> {{ignite.tables().table("public.mytable");}} -> fails with table not found
> {{ignite.tables().table("PUBLIC.MYTABLE ");}} -> returns PUBLIC.MYTABLE
> {{CREATE TABLE \"MyTable\" (id INT, val INT)}}; -> creates PUBLIC.MyTable(ID,
> VAL)
> {{ignite.tables().table("PUBLIC.MyTable");}} -> returns PUBLIC.MyTable
> Tuple / column behavior:
> {{CREATE TABLE MyTable (id INT, \"Id\" INT, val INT)}}; -> creates
> PUBLIC.MYTABLE (ID, Id, VAL)
> {{tbl.get().value("id")}} -> fails with error: column not found
> {{tbl.get().value("ID")}} -> returns ID column's value
> {{tbl.get().value("Id")}} -> returns Id column's value
> *Proposed Fixes*
> *1. Use case insensitive collation to compare and lookup database object*
> e.g.
> {{CREATE TABLE MyTable (id INT, val INT)}}; -> creates PUBLIC.MYTABLE (ID,
> VAL)
> {{ignite.tables().table("public.mytable");}} -> returns PUBLIC.MYTABLE
> {{CREATE TABLE \"MyTable\" (id INT, val INT)}}; -> fails with error:
> PUBLIC.MYTABLE already exists,
> Tuple / column behavior:
> {{CREATE TABLE MyTable (id INT, \"Id\" INT, val INT)}}; -> fails with error:
> duplicate column name: ID
> {{tbl.get().value("id")}} -> returns ID column's value
> {{tbl.get().value("Id")}} -> returns ID column's value
> *2. Case sensitive collation for DB object names and parse string argument of
> the name passed through API*
> Use quotation for string values by API
> {{CREATE TABLE MyTable (id INT, val INT)}}; -> creates PUBLIC.MYTABLE
> {{ignite.tables().table("public.mytable");}} -> returns PUBLIC.MYTABLE
> {{CREATE TABLE \"MyTable\" (id INT, val INT)}}; -> creates PUBLIC.MyTable
> {{ignite.tables().table("public.\"MyTable\"");}} -> returns PUBLIC.MyTable
> Tuple / column behavior:
> {{CREATE TABLE MyTable (id INT, \"Id\" INT, val INT)}}; -> creates
> PUBLIC.MYTABLE (ID, Id, VAL)
> {{tbl.get().value("id")}} -> returns ID column's value
> {{tbl.get().value("Id")}} -> returns ID column's value
> {{tbl.get().value("\"Id\"")}} -> returns Id column's value
--
This message was sent by Atlassian Jira
(v8.20.1#820001)