Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c67bba9

Browse files
committed
Fix another bit of unlogged-table-induced breakage.
Per bug #6205, reported by Abel Abraham Camarillo Ojeda. This isn't a particularly elegant fix, but I'm trying to minimize the chances of causing yet another round of breakage. Adjust regression tests to exercise this case.
1 parent c47e629 commit c67bba9

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

src/backend/catalog/namespace.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ Datum pg_is_other_temp_schema(PG_FUNCTION_ARGS);
221221
Oid
222222
RangeVarGetRelid(const RangeVar *relation, bool failOK)
223223
{
224-
Oid namespaceId;
225224
Oid relId;
226225

227226
/*
@@ -247,17 +246,27 @@ RangeVarGetRelid(const RangeVar *relation, bool failOK)
247246
*/
248247
if (relation->relpersistence == RELPERSISTENCE_TEMP)
249248
{
250-
if (relation->schemaname)
251-
ereport(ERROR,
252-
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
253-
errmsg("temporary tables cannot specify a schema name")));
254-
if (OidIsValid(myTempNamespace))
249+
if (!OidIsValid(myTempNamespace))
250+
relId = InvalidOid; /* this probably can't happen? */
251+
else
252+
{
253+
if (relation->schemaname)
254+
{
255+
Oid namespaceId;
256+
namespaceId = LookupExplicitNamespace(relation->schemaname);
257+
if (namespaceId != myTempNamespace)
258+
ereport(ERROR,
259+
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
260+
errmsg("temporary tables cannot specify a schema name")));
261+
}
262+
255263
relId = get_relname_relid(relation->relname, myTempNamespace);
256-
else /* this probably can't happen? */
257-
relId = InvalidOid;
264+
}
258265
}
259266
else if (relation->schemaname)
260267
{
268+
Oid namespaceId;
269+
261270
/* use exact schema given */
262271
namespaceId = LookupExplicitNamespace(relation->schemaname);
263272
relId = get_relname_relid(relation->relname, namespaceId);

src/test/regress/expected/create_table.out

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,19 @@ CREATE TABLE IF NOT EXISTS test_tsvector(
204204
t text
205205
);
206206
NOTICE: relation "test_tsvector" already exists, skipping
207-
CREATE UNLOGGED TABLE unlogged1 (a int); -- OK
207+
CREATE UNLOGGED TABLE unlogged1 (a int primary key); -- OK
208+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "unlogged1_pkey" for table "unlogged1"
208209
INSERT INTO unlogged1 VALUES (42);
209-
CREATE UNLOGGED TABLE public.unlogged2 (a int); -- also OK
210-
CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int); -- not OK
210+
CREATE UNLOGGED TABLE public.unlogged2 (a int primary key); -- also OK
211+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "unlogged2_pkey" for table "unlogged2"
212+
CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key); -- not OK
211213
ERROR: only temporary relations may be created in temporary schemas
212-
CREATE TABLE pg_temp.implicity_temp (a int); -- OK
213-
CREATE TEMP TABLE explicitly_temp (a int); -- also OK
214-
CREATE TEMP TABLE pg_temp.doubly_temp (a int); -- also OK
215-
CREATE TEMP TABLE public.temp_to_perm (a int); -- not OK
214+
CREATE TABLE pg_temp.implicitly_temp (a int primary key); -- OK
215+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "implicitly_temp_pkey" for table "implicitly_temp"
216+
CREATE TEMP TABLE explicitly_temp (a int primary key); -- also OK
217+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "explicitly_temp_pkey" for table "explicitly_temp"
218+
CREATE TEMP TABLE pg_temp.doubly_temp (a int primary key); -- also OK
219+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "doubly_temp_pkey" for table "doubly_temp"
220+
CREATE TEMP TABLE public.temp_to_perm (a int primary key); -- not OK
216221
ERROR: cannot create temporary relation in non-temporary schema
217222
DROP TABLE unlogged1, public.unlogged2;

src/test/regress/sql/create_table.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ CREATE TABLE IF NOT EXISTS test_tsvector(
241241
t text
242242
);
243243

244-
CREATE UNLOGGED TABLE unlogged1 (a int); -- OK
244+
CREATE UNLOGGED TABLE unlogged1 (a int primary key); -- OK
245245
INSERT INTO unlogged1 VALUES (42);
246-
CREATE UNLOGGED TABLE public.unlogged2 (a int); -- also OK
247-
CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int); -- not OK
248-
CREATE TABLE pg_temp.implicity_temp (a int); -- OK
249-
CREATE TEMP TABLE explicitly_temp (a int); -- also OK
250-
CREATE TEMP TABLE pg_temp.doubly_temp (a int); -- also OK
251-
CREATE TEMP TABLE public.temp_to_perm (a int); -- not OK
246+
CREATE UNLOGGED TABLE public.unlogged2 (a int primary key); -- also OK
247+
CREATE UNLOGGED TABLE pg_temp.unlogged3 (a int primary key); -- not OK
248+
CREATE TABLE pg_temp.implicitly_temp (a int primary key); -- OK
249+
CREATE TEMP TABLE explicitly_temp (a int primary key); -- also OK
250+
CREATE TEMP TABLE pg_temp.doubly_temp (a int primary key); -- also OK
251+
CREATE TEMP TABLE public.temp_to_perm (a int primary key); -- not OK
252252
DROP TABLE unlogged1, public.unlogged2;

0 commit comments

Comments
 (0)