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

Commit 4893552

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 2562dce commit 4893552

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
@@ -225,7 +225,6 @@ RangeVarGetRelid(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok,
225225
bool nowait)
226226
{
227227
uint64 inval_count;
228-
Oid namespaceId;
229228
Oid relId;
230229
Oid oldRelId = InvalidOid;
231230
bool retry = false;
@@ -278,17 +277,27 @@ RangeVarGetRelid(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok,
278277
*/
279278
if (relation->relpersistence == RELPERSISTENCE_TEMP)
280279
{
281-
if (relation->schemaname)
282-
ereport(ERROR,
283-
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
284-
errmsg("temporary tables cannot specify a schema name")));
285-
if (OidIsValid(myTempNamespace))
280+
if (!OidIsValid(myTempNamespace))
281+
relId = InvalidOid; /* this probably can't happen? */
282+
else
283+
{
284+
if (relation->schemaname)
285+
{
286+
Oid namespaceId;
287+
namespaceId = LookupExplicitNamespace(relation->schemaname);
288+
if (namespaceId != myTempNamespace)
289+
ereport(ERROR,
290+
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
291+
errmsg("temporary tables cannot specify a schema name")));
292+
}
293+
286294
relId = get_relname_relid(relation->relname, myTempNamespace);
287-
else /* this probably can't happen? */
288-
relId = InvalidOid;
295+
}
289296
}
290297
else if (relation->schemaname)
291298
{
299+
Oid namespaceId;
300+
292301
/* use exact schema given */
293302
namespaceId = LookupExplicitNamespace(relation->schemaname);
294303
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)