Skip to content

Commit

Permalink
Fix port to PostgreSQL 9.6. Thanks to Devrim Gunduz for the report.
Browse files Browse the repository at this point in the history
  • Loading branch information
darold committed Jun 8, 2021
1 parent f321d9f commit cb55983
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
14 changes: 10 additions & 4 deletions pgtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,14 @@ gtt_check_command(GTT_PROCESSUTILITY_PROTO)
Oid relid;
char *nspname;

relid = RangeVarGetRelidExtended(stmt->relation, ShareLock, 0,
RangeVarCallbackOwnsRelation, NULL);
relid = RangeVarGetRelidExtended(stmt->relation, ShareLock,
#if (PG_VERSION_NUM >= 110000)
0,
#else
false, false,
#endif
RangeVarCallbackOwnsRelation,
NULL);

/* Just take care that the GTT is not in use */
nspname = get_namespace_name(get_rel_namespace(relid));
Expand Down Expand Up @@ -1530,7 +1536,7 @@ create_temporary_table_internal(Oid parent_relid, bool preserved)
{
CommentObject((CommentStmt *) cur_stmt);
}
#if (PG_VERSION_NUM >= 100000)
#if (PG_VERSION_NUM >= 90600)
else if (IsA(cur_stmt, TableLikeClause))
{
TableLikeClause *like = (TableLikeClause *) cur_stmt;
Expand Down Expand Up @@ -1563,7 +1569,7 @@ create_temporary_table_internal(Oid parent_relid, bool preserved)
NULL, NULL,
None_Receiver,
NULL);
#elif PG_VERSION_NUM >= 90500
#else
ProcessUtility(cur_stmt,
"PGTT provide a query string",
PROCESS_UTILITY_SUBCOMMAND,
Expand Down
17 changes: 9 additions & 8 deletions test/expected/05_useindex.out
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ SELECT * FROM t_glob_temptable2;
-- Must complain that the GTT is in use
CREATE INDEX ON t_glob_temptable2 (lbl);
ERROR: a temporary table has been created and is active, can not add an index on the GTT table in this session.
\d pgtt_schema.t_glob_temptable2
Unlogged table "pgtt_schema.t_glob_temptable2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | |
lbl | text | | |
Indexes:
"t_glob_temptable2_id_idx" btree (id)
SELECT pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
WHERE c.oid = 'pgtt_schema.t_glob_temptable2'::regclass::oid AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, c2.relname;
pg_get_indexdef
-----------------------------------------------------------------------------------------
CREATE INDEX t_glob_temptable2_id_idx ON pgtt_schema.t_glob_temptable2 USING btree (id)
(1 row)

\c - -
LOAD 'pgtt';
Expand Down
6 changes: 5 additions & 1 deletion test/sql/05_useindex.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ SELECT * FROM t_glob_temptable2;
-- Must complain that the GTT is in use
CREATE INDEX ON t_glob_temptable2 (lbl);

\d pgtt_schema.t_glob_temptable2
SELECT pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
WHERE c.oid = 'pgtt_schema.t_glob_temptable2'::regclass::oid AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, c2.relname;

\c - -
LOAD 'pgtt';
Expand Down

0 comments on commit cb55983

Please sign in to comment.