ablog

不器用で落着きのない技術者のメモ

Redshift のオブジェクト名の大文字小文字の区別について

検証結果

  • enable_case_sensitive_identifier が true で、DDL やクエリでダブルクオートで囲むと大文字小文字を区別する。
  • enable_case_sensitive_identifier が false だと大文字小文字を区別しない(デフォルトは false)。
  • ダブルクオートで囲まないと小文字として扱われる。

検証ログ

$  psql -a "host=redshift-cluster-poc-central.********.ap-northeast-1.redshift.amazonaws.com user=awsuser dbname=dev port=5439"
psql (13.7, server 8.0.2)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

dev=# \i case_sensitive_test.sql
-- enable_case_sensitive_identifier = false
show enable_case_sensitive_identifier;
 enable_case_sensitive_identifier
----------------------------------
 off
(1 row)

create table "TEST_UC" ("ID" INT);
CREATE TABLE
create table "test_lc" ("id" int);
CREATE TABLE
select id from test_uc;
 id
----
(0 rows)

select ID from TEST_UC;
 id
----
(0 rows)

select "ID" from "TEST_UC";
 id
----
(0 rows)

select id from test_lc;
 id
----
(0 rows)

select ID from TEST_LC;
 id
----
(0 rows)

select "ID" from "TEST_LC";
 id
----
(0 rows)

drop table test_uc;
DROP TABLE
drop table test_lc;
DROP TABLE
-- enable_case_sensitive_identifier = true
set enable_case_sensitive_identifier to true;
SET
show enable_case_sensitive_identifier;
 enable_case_sensitive_identifier
----------------------------------
 on
(1 row)

create table "TEST_UC" ("ID" INT);
CREATE TABLE
create table "test_lc" ("id" int);
CREATE TABLE
select id from test_uc;
psql:case_sensitive_test.sql:25: ERROR:  relation "test_uc" does not exist
select ID from TEST_UC;
psql:case_sensitive_test.sql:26: ERROR:  relation "test_uc" does not exist
select "ID" from "TEST_UC";
 ID
----
(0 rows)

select id from test_lc;
 id
----
(0 rows)

select ID from TEST_LC;
 id
----
(0 rows)

select "ID" from "TEST_LC";
psql:case_sensitive_test.sql:31: ERROR:  relation "TEST_LC" does not exist
drop table "TEST_UC";
DROP TABLE
drop table "test_lc";
DROP TABLE
dev=#