agora inbox for [email protected]
help / color / mirror / Atom feedAllow to_date() and to_timestamp() to accept localized names
325+ messages / 3 participants
[nested] [flat]
* Allow to_date() and to_timestamp() to accept localized names
@ 2019-08-18 08:42 Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
0 siblings, 1 reply; 325+ messages in thread
From: Juan José Santamaría Flecha @ 2019-08-18 08:42 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
Hello,
Going through the current items in the wiki's todo list, I have been
looking into: "Allow to_date () and to_timestamp () to accept
localized month names".
It seems to me that the code is almost there, so I would like to know
if something like the attached patch would be a reasonable way to go.
Regards,
Juan José Santamaría Flecha
Attachments:
[application/octet-stream] 0001-Allow-localized-month-names-to_date.patch (14.9K, ../../CAC+AXB3u1jTngJcoC1nAHBf=M3v-jrEfo86UFtCqCjzbWS9QhA@mail.gmail.com/2-0001-Allow-localized-month-names-to_date.patch)
download | inline diff:
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 7412df0..2e2aa38 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -6387,8 +6387,17 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
<listitem>
<para>
<literal>TM</literal> does not include trailing blanks.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
<function>to_timestamp</function> and <function>to_date</function> ignore
- the <literal>TM</literal> modifier.
+ the case when receiving names as an input. For example, either
+ <literal>to_timestamp('2000-JUN', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-Jun', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-JUN', 'YYYY-mon')</literal> work and return
+ the same output.
</para>
</listitem>
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index b3115e4..90c707b 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -174,6 +174,13 @@ typedef struct
#define CLOCK_24_HOUR 0
#define CLOCK_12_HOUR 1
+/* ----------
+ * Dimension for seq_search.
+ * ----------
+ */
+#define MONTHS_DIM 12
+#define DAYS_DIM 7
+#define AD_AM_DIM 4
/* ----------
* Full months
@@ -181,11 +188,11 @@ typedef struct
*/
static const char *const months_full[] = {
"January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December", NULL
+ "August", "September", "October", "November", "December"
};
static const char *const days_short[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
/* ----------
@@ -217,8 +224,8 @@ static const char *const days_short[] = {
* matches for BC have an odd index. So the boolean value for BC is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR, NULL};
-static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR, NULL};
+static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR};
+static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR};
/* ----------
* AM / PM
@@ -244,8 +251,8 @@ static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_S
* matches for PM have an odd index. So the boolean value for PM is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR, NULL};
-static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR, NULL};
+static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR};
+static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR};
/* ----------
* Months in roman-numeral
@@ -254,10 +261,10 @@ static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_S
* ----------
*/
static const char *const rm_months_upper[] =
-{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I", NULL};
+{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I"};
static const char *const rm_months_lower[] =
-{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i", NULL};
+{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i"};
/* ----------
* Roman numbers
@@ -975,7 +982,7 @@ static void parse_format(FormatNode *node, const char *str, const KeyWord *kw,
static void DCH_to_char(FormatNode *node, bool is_interval,
TmToChar *in, char *out, Oid collid);
-static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out);
+static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid);
#ifdef DEBUG_TO_FROM_CHAR
static void dump_index(const KeyWord *k, const int *index);
@@ -990,10 +997,11 @@ static void from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode);
static void from_char_set_int(int *dest, const int value, const FormatNode *node);
static int from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node);
static int from_char_parse_int(int *dest, char **src, FormatNode *node);
-static int seq_search(char *name, const char *const *array, int type, int max, int *len);
-static int from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max, FormatNode *node);
+static int seq_search(char *name, const char *const *array, int type, int max, int dim, int *len, Oid collid);
+static int from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max, int dim,
+ FormatNode *node, Oid collid);
static void do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec);
+ struct pg_tm *tm, fsec_t *fsec, Oid collid);
static char *fill_str(char *str, int c, int max);
static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree);
static char *int_to_roman(int number);
@@ -2326,13 +2334,17 @@ from_char_parse_int(int *dest, char **src, FormatNode *node)
* ----------
*/
static int
-seq_search(char *name, const char *const *array, int type, int max, int *len)
+seq_search(char *name, const char *const *array, int type, int max, int dim, int *len, Oid collid)
{
const char *p;
const char *const *a;
char *n;
int last,
i;
+ int index;
+ int mb_max;
+ char *initcap_name;
+ const char *localized_name;
*len = 0;
@@ -2345,25 +2357,37 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
else if (type == ALL_LOWER)
*name = pg_tolower((unsigned char) *name);
- for (last = 0, a = array; *a != NULL; a++)
+ for (last = 0, a = array, index = 0; index < dim; a++, index++)
{
+ /* Do not make assumptions about localized names case and length */
+ if (lc_ctype_is_c(collid))
+ {
+ localized_name = *a;
+ mb_max = max;
+ }
+ else
+ {
+ initcap_name = str_initcap_z(*a, collid);
+ localized_name = initcap_name;
+ mb_max = max * MAX_MULTIBYTE_CHAR_LEN;
+ }
/* compare first chars */
- if (*name != **a)
+ if (*name != *localized_name)
continue;
- for (i = 1, p = *a + 1, n = name + 1;; n++, p++, i++)
+ for (i = 1, p = localized_name + 1, n = name + 1;; n++, p++, i++)
{
/* search fragment (max) only */
- if (max && i == max)
+ if (mb_max && i == mb_max)
{
*len = i;
- return a - array;
+ return index;
}
/* full size */
if (*p == '\0')
{
*len = i;
- return a - array;
+ return index;
}
/* Not found in array 'a' */
if (*n == '\0')
@@ -2383,7 +2407,7 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
#ifdef DEBUG_TO_FROM_CHAR
elog(DEBUG_elog_output, "N: %c, P: %c, A: %s (%s)",
- *n, *p, *a, name);
+ *n, *p, localized_name, name);
#endif
if (*n != *p)
break;
@@ -2404,12 +2428,12 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
* If the string doesn't match, throw an error.
*/
static int
-from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max,
- FormatNode *node)
+from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max, int dim,
+ FormatNode *node, Oid collid)
{
int len;
- *dest = seq_search(*src, array, type, max, &len);
+ *dest = seq_search(*src, array, type, max, dim, &len, collid);
if (len <= 0)
{
char copy[DCH_MAX_ITEM_SIZ + 1];
@@ -3014,7 +3038,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
* ----------
*/
static void
-DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
+DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid)
{
FormatNode *n;
char *s;
@@ -3024,6 +3048,8 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
/* number of extra skipped characters (more than given in format string) */
int extra_skip = 0;
+ /* cache localized days and months */
+ cache_locale_time();
for (n = node, s = in; n->type != NODE_TYPE_END && *s != '\0'; n++)
{
@@ -3109,7 +3135,7 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_a_m:
case DCH_p_m:
from_char_seq_search(&value, &s, ampm_strings_long,
- ALL_UPPER, n->key->len, n);
+ ALL_UPPER, n->key->len, AD_AM_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3118,7 +3144,7 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_am:
case DCH_pm:
from_char_seq_search(&value, &s, ampm_strings,
- ALL_UPPER, n->key->len, n);
+ ALL_UPPER, n->key->len, AD_AM_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3209,7 +3235,7 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_a_d:
case DCH_b_c:
from_char_seq_search(&value, &s, adbc_strings_long,
- ALL_UPPER, n->key->len, n);
+ ALL_UPPER, n->key->len, AD_AM_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_AD:
@@ -3217,21 +3243,29 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_ad:
case DCH_bc:
from_char_seq_search(&value, &s, adbc_strings,
- ALL_UPPER, n->key->len, n);
+ ALL_UPPER, n->key->len, AD_AM_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_MONTH:
case DCH_Month:
case DCH_month:
- from_char_seq_search(&value, &s, months_full, ONE_UPPER,
- MAX_MONTH_LEN, n);
+ if (S_TM(n->suffix))
+ from_char_seq_search(&value, &s, (const char * const*)localized_full_months, ONE_UPPER,
+ MAX_MONTH_LEN, MONTHS_DIM, n, collid);
+ else
+ from_char_seq_search(&value, &s, months_full, ONE_UPPER,
+ MAX_MONTH_LEN, MONTHS_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MON:
case DCH_Mon:
case DCH_mon:
- from_char_seq_search(&value, &s, months, ONE_UPPER,
- MAX_MON_LEN, n);
+ if (S_TM(n->suffix))
+ from_char_seq_search(&value, &s, (const char * const*)localized_abbrev_months, ONE_UPPER,
+ MAX_MON_LEN, MONTHS_DIM, n, collid);
+ else
+ from_char_seq_search(&value, &s, months, ONE_UPPER,
+ MAX_MON_LEN, MONTHS_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MM:
@@ -3241,16 +3275,24 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_DAY:
case DCH_Day:
case DCH_day:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DAY_LEN, n);
+ if (S_TM(n->suffix))
+ from_char_seq_search(&value, &s, (const char * const*)localized_full_days, ONE_UPPER,
+ MAX_DAY_LEN, DAYS_DIM, n, collid);
+ else
+ from_char_seq_search(&value, &s, days, ONE_UPPER,
+ MAX_DAY_LEN, DAYS_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->d, value, n);
out->d++;
break;
case DCH_DY:
case DCH_Dy:
case DCH_dy:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DY_LEN, n);
+ if (S_TM(n->suffix))
+ from_char_seq_search(&value, &s, (const char * const*)localized_abbrev_days, ONE_UPPER,
+ MAX_DY_LEN, DAYS_DIM, n, collid);
+ else
+ from_char_seq_search(&value, &s, days_short, ONE_UPPER,
+ MAX_DY_LEN, DAYS_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->d, value, n);
out->d++;
break;
@@ -3349,12 +3391,12 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
break;
case DCH_RM:
from_char_seq_search(&value, &s, rm_months_upper,
- ALL_UPPER, MAX_RM_LEN, n);
+ ALL_UPPER, MAX_RM_LEN, MONTHS_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_rm:
from_char_seq_search(&value, &s, rm_months_lower,
- ALL_LOWER, MAX_RM_LEN, n);
+ ALL_LOWER, MAX_RM_LEN, MONTHS_DIM, n, C_COLLATION_OID);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_W:
@@ -3687,7 +3729,7 @@ to_timestamp(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Use the specified time zone, if any. */
if (tm.tm_zone)
@@ -3722,7 +3764,7 @@ to_date(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Prevent overflow in Julian-day routines */
if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))
@@ -3758,7 +3800,7 @@ to_date(PG_FUNCTION_ARGS)
*/
static void
do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec)
+ struct pg_tm *tm, fsec_t *fsec, Oid collid)
{
FormatNode *format;
TmFromChar tmfc;
@@ -3807,11 +3849,11 @@ do_to_timestamp(text *date_txt, text *fmt,
}
#ifdef DEBUG_TO_FROM_CHAR
- /* dump_node(format, fmt_len); */
- /* dump_index(DCH_keywords, DCH_index); */
+ dump_node(format, fmt_len);
+ dump_index(DCH_keywords, DCH_index);
#endif
- DCH_from_char(format, date_str, &tmfc);
+ DCH_from_char(format, date_str, &tmfc, collid);
pfree(fmt_str);
if (!incache)
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index ad56ff9..1e0161b 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -461,6 +461,18 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
01 NİS 2010
(1 row)
+-- to_date
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY');
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+ERROR: invalid value "123456789" for "MONTH"
+DETAIL: The given value did not match any of the allowed values for this field.
-- backwards parsing
CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc';
CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C";
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index eac2f90..1c734d2 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -182,6 +182,13 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR");
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY');
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
+-- to_date
+
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY');
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+
-- backwards parsing
^ permalink raw reply [nested|flat] 325+ messages in thread
* Re: Allow to_date() and to_timestamp() to accept localized names
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
@ 2019-08-22 19:38 ` Juan José Santamaría Flecha <[email protected]>
2019-08-23 08:33 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-13 20:31 ` Re: Allow to_date() and to_timestamp() to accept localized names Alvaro Herrera <[email protected]>
0 siblings, 2 replies; 325+ messages in thread
From: Juan José Santamaría Flecha @ 2019-08-22 19:38 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
On Sun, Aug 18, 2019 at 10:42 AM Juan José Santamaría Flecha
<[email protected]> wrote:
>
> Going through the current items in the wiki's todo list, I have been
> looking into: "Allow to_date () and to_timestamp () to accept
> localized month names".
>
I have gone through a second take on this, trying to give it a better
shape but it would surely benefit from some review, so I will open an
item in the commitfest.
Regards,
Juan José Santamaría Flecha
Attachments:
[application/octet-stream] 0001-Allow-localized-month-names-to_date-v1.patch (17.3K, ../../CAC+AXB0AMzuaPddH+N5AHZ=sdGzJPmqYL=zSG5ARACzkZfhF3w@mail.gmail.com/2-0001-Allow-localized-month-names-to_date-v1.patch)
download | inline diff:
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 7412df0..2e2aa38 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -6387,8 +6387,17 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
<listitem>
<para>
<literal>TM</literal> does not include trailing blanks.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
<function>to_timestamp</function> and <function>to_date</function> ignore
- the <literal>TM</literal> modifier.
+ the case when receiving names as an input. For example, either
+ <literal>to_timestamp('2000-JUN', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-Jun', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-JUN', 'YYYY-mon')</literal> work and return
+ the same output.
</para>
</listitem>
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index b3115e4..9d6ab1a 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -174,6 +174,13 @@ typedef struct
#define CLOCK_24_HOUR 0
#define CLOCK_12_HOUR 1
+/* ----------
+ * Dimension for seq_search.
+ * ----------
+ */
+#define MONTHS_DIM 12
+#define DAYS_DIM 7
+#define AD_AM_DIM 4
/* ----------
* Full months
@@ -181,11 +188,11 @@ typedef struct
*/
static const char *const months_full[] = {
"January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December", NULL
+ "August", "September", "October", "November", "December"
};
static const char *const days_short[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
/* ----------
@@ -217,8 +224,8 @@ static const char *const days_short[] = {
* matches for BC have an odd index. So the boolean value for BC is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR, NULL};
-static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR, NULL};
+static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR};
+static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR};
/* ----------
* AM / PM
@@ -244,8 +251,8 @@ static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_S
* matches for PM have an odd index. So the boolean value for PM is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR, NULL};
-static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR, NULL};
+static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR};
+static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR};
/* ----------
* Months in roman-numeral
@@ -254,10 +261,10 @@ static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_S
* ----------
*/
static const char *const rm_months_upper[] =
-{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I", NULL};
+{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I"};
static const char *const rm_months_lower[] =
-{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i", NULL};
+{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i"};
/* ----------
* Roman numbers
@@ -975,7 +982,7 @@ static void parse_format(FormatNode *node, const char *str, const KeyWord *kw,
static void DCH_to_char(FormatNode *node, bool is_interval,
TmToChar *in, char *out, Oid collid);
-static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out);
+static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid);
#ifdef DEBUG_TO_FROM_CHAR
static void dump_index(const KeyWord *k, const int *index);
@@ -990,10 +997,13 @@ static void from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode);
static void from_char_set_int(int *dest, const int value, const FormatNode *node);
static int from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node);
static int from_char_parse_int(int *dest, char **src, FormatNode *node);
-static int seq_search(char *name, const char *const *array, int type, int max, int *len);
-static int from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max, FormatNode *node);
+static bool str_compare(char *name, const char *element, int type, int max, int *len, int *last);
+static int seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim);
+static int seq_search_localized(char *name, char **array, int type, int max, int *len, int dim, Oid collid);
+static int from_char_seq_search(int *dest, char **src, const char *const *array, char **localized_array, int type, int max,
+ FormatNode *node, int dim, Oid collid);
static void do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec);
+ struct pg_tm *tm, fsec_t *fsec, Oid collid);
static char *fill_str(char *str, int c, int max);
static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree);
static char *int_to_roman(int number);
@@ -2322,17 +2332,66 @@ from_char_parse_int(int *dest, char **src, FormatNode *node)
}
/* ----------
- * Sequential search with to upper/lower conversion
+ * Compares 'name' with array 'element' applying to upper/lower conversion,
+ * utility function for seq_search
* ----------
*/
-static int
-seq_search(char *name, const char *const *array, int type, int max, int *len)
+static bool
+str_compare(char *name, const char *element, int type, int max, int *len, int *last)
{
const char *p;
- const char *const *a;
char *n;
- int last,
- i;
+ int i;
+
+ for (i = 1, p = element + 1, n = name + 1;; n++, p++, i++)
+ {
+ /* search fragment (max) only */
+ if (max && i == max)
+ {
+ *len = i;
+ return true;
+ }
+ /* full size */
+ if (*p == '\0')
+ {
+ *len = i;
+ return true;
+ }
+ /* Not found in array 'a' */
+ if (*n == '\0')
+ return false;
+
+ /*
+ * Convert (but convert new chars only)
+ */
+ if (i > *last)
+ {
+ if (type == ONE_UPPER || type == ALL_LOWER)
+ *n = pg_tolower((unsigned char) *n);
+ else if (type == ALL_UPPER)
+ *n = pg_toupper((unsigned char) *n);
+ *last = i;
+ }
+
+#ifdef DEBUG_TO_FROM_CHAR
+ elog(DEBUG_elog_output, "N: %c, P: %c, A: %s (%s)",
+ *n, *p, element, name);
+#endif
+ if (*n != *p)
+ return false;
+ }
+}
+
+/* ----------
+ * Sequential search with to upper/lower conversion for SQL_ASCII array input
+ * ----------
+ */
+static int
+seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim)
+{
+ const char *const *a;
+ int last;
+ int index;
*len = 0;
@@ -2345,49 +2404,51 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
else if (type == ALL_LOWER)
*name = pg_tolower((unsigned char) *name);
- for (last = 0, a = array; *a != NULL; a++)
+ for (last = 0, a = array, index = 0; index < dim; a++, index++)
{
/* compare first chars */
if (*name != **a)
continue;
+ if (str_compare(name, *a, type, max, len, &last))
+ return index;
+ }
- for (i = 1, p = *a + 1, n = name + 1;; n++, p++, i++)
- {
- /* search fragment (max) only */
- if (max && i == max)
- {
- *len = i;
- return a - array;
- }
- /* full size */
- if (*p == '\0')
- {
- *len = i;
- return a - array;
- }
- /* Not found in array 'a' */
- if (*n == '\0')
- break;
+ return -1;
+}
- /*
- * Convert (but convert new chars only)
- */
- if (i > last)
- {
- if (type == ONE_UPPER || type == ALL_LOWER)
- *n = pg_tolower((unsigned char) *n);
- else if (type == ALL_UPPER)
- *n = pg_toupper((unsigned char) *n);
- last = i;
- }
+/* ----------
+ * Sequential search with to upper/lower conversion for localized array input
+ * ----------
+ */
+static int
+seq_search_localized(char *name, char **array, int type, int max, int *len, int dim, Oid collid)
+{
+ char **a;
+ char *initcap;
+ int last;
+ int index;
+ int mb_max;
-#ifdef DEBUG_TO_FROM_CHAR
- elog(DEBUG_elog_output, "N: %c, P: %c, A: %s (%s)",
- *n, *p, *a, name);
-#endif
- if (*n != *p)
- break;
- }
+ *len = 0;
+
+ if (!*name)
+ return -1;
+
+ /* set first char */
+ if (type == ONE_UPPER || type == ALL_UPPER)
+ *name = pg_toupper((unsigned char) *name);
+ else if (type == ALL_LOWER)
+ *name = pg_tolower((unsigned char) *name);
+
+ mb_max = max * pg_database_encoding_max_length();
+ for (last = 0, a = array, index = 0; index < dim; a++, index++)
+ {
+ /* compare first chars */
+ if (*name != **a)
+ continue;
+ initcap = str_initcap_z(*a, collid);
+ if (str_compare(name, initcap, type, mb_max, len, &last))
+ return index;
}
return -1;
@@ -2404,16 +2465,20 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
* If the string doesn't match, throw an error.
*/
static int
-from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max,
- FormatNode *node)
+from_char_seq_search(int *dest, char **src, const char *const *array, char **localized_array, int type, int max,
+ FormatNode *node, int dim, Oid collid)
{
int len;
- *dest = seq_search(*src, array, type, max, &len);
+ if (localized_array == NULL)
+ *dest = seq_search_sqlascii(*src, array, type, max, &len, dim);
+ else
+ *dest = seq_search_localized(*src, localized_array, type, max, &len, dim, collid);
if (len <= 0)
{
char copy[DCH_MAX_ITEM_SIZ + 1];
+ /* We use byte length, localized names encoding is ignored */
Assert(max <= DCH_MAX_ITEM_SIZ);
strlcpy(copy, *src, max + 1);
@@ -3014,19 +3079,24 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
* ----------
*/
static void
-DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
+DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid)
{
FormatNode *n;
char *s;
int len,
value;
bool fx_mode = false;
+ char **localized_names;
/* number of extra skipped characters (more than given in format string) */
int extra_skip = 0;
+ /* cache localized days and months */
+ cache_locale_time();
for (n = node, s = in; n->type != NODE_TYPE_END && *s != '\0'; n++)
{
+ localized_names = NULL;
+
/*
* Ignore spaces at the beginning of the string and before fields when
* not in FX (fixed width) mode.
@@ -3108,8 +3178,8 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_P_M:
case DCH_a_m:
case DCH_p_m:
- from_char_seq_search(&value, &s, ampm_strings_long,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, ampm_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, AD_AM_DIM, collid);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3117,8 +3187,8 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_PM:
case DCH_am:
case DCH_pm:
- from_char_seq_search(&value, &s, ampm_strings,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, ampm_strings, localized_names,
+ ALL_UPPER, n->key->len, n, AD_AM_DIM, collid);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3208,30 +3278,34 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_B_C:
case DCH_a_d:
case DCH_b_c:
- from_char_seq_search(&value, &s, adbc_strings_long,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, adbc_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, AD_AM_DIM, collid);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_AD:
case DCH_BC:
case DCH_ad:
case DCH_bc:
- from_char_seq_search(&value, &s, adbc_strings,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, adbc_strings, localized_names,
+ ALL_UPPER, n->key->len, n, AD_AM_DIM, collid);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_MONTH:
case DCH_Month:
case DCH_month:
- from_char_seq_search(&value, &s, months_full, ONE_UPPER,
- MAX_MONTH_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_months;
+ from_char_seq_search(&value, &s, months_full, localized_names,
+ ONE_UPPER, MAX_MONTH_LEN, n, MONTHS_DIM, collid);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MON:
case DCH_Mon:
case DCH_mon:
- from_char_seq_search(&value, &s, months, ONE_UPPER,
- MAX_MON_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_months;
+ from_char_seq_search(&value, &s, months, localized_names,
+ ONE_UPPER, MAX_MON_LEN, n, MONTHS_DIM, collid);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MM:
@@ -3241,16 +3315,20 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_DAY:
case DCH_Day:
case DCH_day:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DAY_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_days;
+ from_char_seq_search(&value, &s, days, localized_names,
+ ONE_UPPER, MAX_DAY_LEN, n, DAYS_DIM, collid);
from_char_set_int(&out->d, value, n);
out->d++;
break;
case DCH_DY:
case DCH_Dy:
case DCH_dy:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DY_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_days;
+ from_char_seq_search(&value, &s, days_short, localized_names,
+ ONE_UPPER, MAX_DY_LEN, n, DAYS_DIM, collid);
from_char_set_int(&out->d, value, n);
out->d++;
break;
@@ -3348,13 +3426,13 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
SKIP_THth(s, n->suffix);
break;
case DCH_RM:
- from_char_seq_search(&value, &s, rm_months_upper,
- ALL_UPPER, MAX_RM_LEN, n);
+ from_char_seq_search(&value, &s, rm_months_upper, localized_names,
+ ALL_UPPER, MAX_RM_LEN, n, MONTHS_DIM, collid);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_rm:
- from_char_seq_search(&value, &s, rm_months_lower,
- ALL_LOWER, MAX_RM_LEN, n);
+ from_char_seq_search(&value, &s, rm_months_lower, localized_names,
+ ALL_LOWER, MAX_RM_LEN, n, MONTHS_DIM, collid);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_W:
@@ -3687,7 +3765,7 @@ to_timestamp(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Use the specified time zone, if any. */
if (tm.tm_zone)
@@ -3722,7 +3800,7 @@ to_date(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Prevent overflow in Julian-day routines */
if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))
@@ -3758,7 +3836,7 @@ to_date(PG_FUNCTION_ARGS)
*/
static void
do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec)
+ struct pg_tm *tm, fsec_t *fsec, Oid collid)
{
FormatNode *format;
TmFromChar tmfc;
@@ -3807,11 +3885,11 @@ do_to_timestamp(text *date_txt, text *fmt,
}
#ifdef DEBUG_TO_FROM_CHAR
- /* dump_node(format, fmt_len); */
- /* dump_index(DCH_keywords, DCH_index); */
+ dump_node(format, fmt_len);
+ dump_index(DCH_keywords, DCH_index);
#endif
- DCH_from_char(format, date_str, &tmfc);
+ DCH_from_char(format, date_str, &tmfc, collid);
pfree(fmt_str);
if (!incache)
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index ad56ff9..1e0161b 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -461,6 +461,18 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
01 NİS 2010
(1 row)
+-- to_date
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY');
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+ERROR: invalid value "123456789" for "MONTH"
+DETAIL: The given value did not match any of the allowed values for this field.
-- backwards parsing
CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc';
CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C";
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index eac2f90..1c734d2 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -182,6 +182,13 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR");
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY');
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
+-- to_date
+
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY');
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+
-- backwards parsing
^ permalink raw reply [nested|flat] 325+ messages in thread
* Re: Allow to_date() and to_timestamp() to accept localized names
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
@ 2019-08-23 08:33 ` Juan José Santamaría Flecha <[email protected]>
1 sibling, 0 replies; 325+ messages in thread
From: Juan José Santamaría Flecha @ 2019-08-23 08:33 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
On Thu, Aug 22, 2019 at 9:38 PM Juan José Santamaría Flecha
<[email protected]> wrote:
>
> >
> > Going through the current items in the wiki's todo list, I have been
> > looking into: "Allow to_date () and to_timestamp () to accept
> > localized month names".
> >
>
> I have gone through a second take on this, trying to give it a better
> shape but it would surely benefit from some review, so I will open an
> item in the commitfest.
For reviewers, the current aproach for this patch is:
Break seq_search() into two functions:
* seq_search_sqlascii() that supports seq_search() current usage.
* seq_search_localized() similar to the previous but supports multibyte input.
To avoid code duplication most of current seq_search() logic has been
moved to a new function str_compare().
from_char_seq_search() is now responsible to choose between
seq_search_sqlascii() or seq_search_localized().
Also, since localized names is not a null terminated array,
seq_search() now receives the dimension as input and terminating nulls
have been removed from static arrays.
The commitfest item is:
https://commitfest.postgresql.org/24/2255/
Regards,
Juan José Santamaría Flecha
^ permalink raw reply [nested|flat] 325+ messages in thread
* Re: Allow to_date() and to_timestamp() to accept localized names
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
@ 2019-09-13 20:31 ` Alvaro Herrera <[email protected]>
2019-09-18 09:09 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
1 sibling, 1 reply; 325+ messages in thread
From: Alvaro Herrera @ 2019-09-13 20:31 UTC (permalink / raw)
To: Juan José Santamaría Flecha <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On 2019-Aug-22, Juan José Santamaría Flecha wrote:
> On Sun, Aug 18, 2019 at 10:42 AM Juan José Santamaría Flecha
> <[email protected]> wrote:
> >
> > Going through the current items in the wiki's todo list, I have been
> > looking into: "Allow to_date () and to_timestamp () to accept
> > localized month names".
>
> I have gone through a second take on this, trying to give it a better
> shape but it would surely benefit from some review, so I will open an
> item in the commitfest.
I'm confused why we acquire the MONTH_DIM / etc definitions. Can't we
just use lengthof() of the corresponding array? AFAICS it should work
just as well.
I wonder if the "compare first char" thing (seq_search_localized) really
works when there are multibyte chars in the day/month names. I think
the code compares just the first char ... but what if the original
string uses those funny Unicode non-normalized letters and the locale
translation uses normalized letters? My guess is that the first-char
comparison will fail, but surely you'll want the name to match.
(There's no month/day name in Spanish that doesn't start with an ASCII
letter, but I bet there are some in other languages.) I think the
localized comparison should avoid the first-char optimization, just
compare the whole string all the time, and avoid possible weird issues.
But then, I'm not 100% sure of this code. formatting.c is madness
distilled.
Thanks,
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 325+ messages in thread
* Re: Allow to_date() and to_timestamp() to accept localized names
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-13 20:31 ` Re: Allow to_date() and to_timestamp() to accept localized names Alvaro Herrera <[email protected]>
@ 2019-09-18 09:09 ` Juan José Santamaría Flecha <[email protected]>
2019-09-22 12:33 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
0 siblings, 1 reply; 325+ messages in thread
From: Juan José Santamaría Flecha @ 2019-09-18 09:09 UTC (permalink / raw)
To: Alvaro Herrera <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Fri, Sep 13, 2019 at 10:31 PM Alvaro Herrera
<[email protected]> wrote:
>
Thanks for taking a look at this.
> I'm confused why we acquire the MONTH_DIM / etc definitions. Can't we
> just use lengthof() of the corresponding array? AFAICS it should work
> just as well.
>
It was because of the length difference between ascii-name arrays,
which were all null-ended, and localized-name arrays. The attached
version uses lengthof().
> I wonder if the "compare first char" thing (seq_search_localized) really
> works when there are multibyte chars in the day/month names. I think
> the code compares just the first char ... but what if the original
> string uses those funny Unicode non-normalized letters and the locale
> translation uses normalized letters? My guess is that the first-char
> comparison will fail, but surely you'll want the name to match.
> (There's no month/day name in Spanish that doesn't start with an ASCII
> letter, but I bet there are some in other languages.) I think the
> localized comparison should avoid the first-char optimization, just
> compare the whole string all the time, and avoid possible weird issues.
The localized search is reformulated in this version to deal with
multibyte normalization. A regression test for this issue is included.
Regards,
Juan José Santamaría Flecha
Attachments:
[application/octet-stream] 0001-Allow-localized-month-names-to_date-v2.patch (17.4K, ../../CAC+AXB1ao4uniAXNnWU3uyq6Ks=nyKq5MwzrFM8sw_MLUF+E=Q@mail.gmail.com/2-0001-Allow-localized-month-names-to_date-v2.patch)
download | inline diff:
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 4e3e213..c470c0e 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -6415,8 +6415,17 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
<listitem>
<para>
<literal>TM</literal> does not include trailing blanks.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
<function>to_timestamp</function> and <function>to_date</function> ignore
- the <literal>TM</literal> modifier.
+ the case when receiving names as an input. For example, either
+ <literal>to_timestamp('2000-JUN', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-Jun', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-JUN', 'YYYY-mon')</literal> work and return
+ the same output.
</para>
</listitem>
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 755ca6e..23f0610 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -96,6 +96,7 @@
#include "utils/memutils.h"
#include "utils/numeric.h"
#include "utils/pg_locale.h"
+#include "common/unicode_norm.h"
/* ----------
* Routines type
@@ -174,18 +175,17 @@ typedef struct
#define CLOCK_24_HOUR 0
#define CLOCK_12_HOUR 1
-
/* ----------
* Full months
* ----------
*/
static const char *const months_full[] = {
"January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December", NULL
+ "August", "September", "October", "November", "December"
};
static const char *const days_short[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
/* ----------
@@ -217,8 +217,8 @@ static const char *const days_short[] = {
* matches for BC have an odd index. So the boolean value for BC is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR, NULL};
-static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR, NULL};
+static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR};
+static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR};
/* ----------
* AM / PM
@@ -244,8 +244,8 @@ static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_S
* matches for PM have an odd index. So the boolean value for PM is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR, NULL};
-static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR, NULL};
+static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR};
+static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR};
/* ----------
* Months in roman-numeral
@@ -254,10 +254,10 @@ static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_S
* ----------
*/
static const char *const rm_months_upper[] =
-{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I", NULL};
+{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I"};
static const char *const rm_months_lower[] =
-{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i", NULL};
+{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i"};
/* ----------
* Roman numbers
@@ -975,7 +975,7 @@ static void parse_format(FormatNode *node, const char *str, const KeyWord *kw,
static void DCH_to_char(FormatNode *node, bool is_interval,
TmToChar *in, char *out, Oid collid);
-static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out);
+static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid);
#ifdef DEBUG_TO_FROM_CHAR
static void dump_index(const KeyWord *k, const int *index);
@@ -990,10 +990,12 @@ static void from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode);
static void from_char_set_int(int *dest, const int value, const FormatNode *node);
static int from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node);
static int from_char_parse_int(int *dest, char **src, FormatNode *node);
-static int seq_search(char *name, const char *const *array, int type, int max, int *len);
-static int from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max, FormatNode *node);
+static int seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim);
+static int seq_search_localized(char *name, char **array, int max, int *len, int dim, Oid collid);
+static int from_char_seq_search(int *dest, char **src, const char *const *array, char **localized_array, int type, int max,
+ FormatNode *node, int dim, Oid collid);
static void do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec);
+ struct pg_tm *tm, fsec_t *fsec, Oid collid);
static char *fill_str(char *str, int c, int max);
static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree);
static char *int_to_roman(int number);
@@ -2325,17 +2327,18 @@ from_char_parse_int(int *dest, char **src, FormatNode *node)
}
/* ----------
- * Sequential search with to upper/lower conversion
+ * Sequential search with to upper/lower conversion for SQL_ASCII array input
* ----------
*/
static int
-seq_search(char *name, const char *const *array, int type, int max, int *len)
+seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim)
{
const char *p;
const char *const *a;
char *n;
int last,
i;
+ int index;
*len = 0;
@@ -2348,7 +2351,7 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
else if (type == ALL_LOWER)
*name = pg_tolower((unsigned char) *name);
- for (last = 0, a = array; *a != NULL; a++)
+ for (last = 0, a = array, index = 0; index < dim; a++, index++)
{
/* compare first chars */
if (*name != **a)
@@ -2360,13 +2363,13 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
if (max && i == max)
{
*len = i;
- return a - array;
+ return index;
}
/* full size */
if (*p == '\0')
{
*len = i;
- return a - array;
+ return index;
}
/* Not found in array 'a' */
if (*n == '\0')
@@ -2396,6 +2399,83 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
return -1;
}
+/* ----------
+ * Sequential search with initcap conversion for localized array input
+ * ----------
+ */
+static int
+seq_search_localized(char *name, char **array, int max, int *len, int dim, Oid collid)
+{
+ char **a;
+ char *initcap_element;
+ char *initcap_name;
+ char *norm_name;
+ int index;
+ int mb_max;
+ int name_len;
+ int norm_len;
+ int element_len;
+ pg_wchar *wchar_name;
+ pg_wchar *norm_wname;
+ size_t name_wlen;
+ size_t norm_wlen;
+
+ *len = 0;
+
+ if (!*name)
+ return -1;
+
+ mb_max = max * pg_database_encoding_max_length();
+ name_len = strlen(name);
+ name_len = name_len < mb_max ? name_len : mb_max;
+
+ /* Normalize and initcap name */
+ wchar_name = (pg_wchar *) palloc((name_len + 1) * sizeof(pg_wchar));
+ name_wlen = pg_mb2wchar_with_len(name, wchar_name, name_len);
+ norm_wname = unicode_normalize_kc(wchar_name);
+ pfree(wchar_name);
+ norm_wlen = pg_wchar_strlen(norm_wname);
+ if (name_wlen == norm_wlen)
+ {
+ norm_name = name;
+ norm_len = name_len;
+ }
+ else
+ {
+ norm_name = (char *) palloc((norm_wlen + 1) * sizeof(pg_wchar));
+ norm_len = pg_wchar2mb_with_len(norm_wname, norm_name, norm_wlen);
+ }
+ pfree(norm_wname);
+ initcap_name = str_initcap(norm_name, norm_len, collid);
+ if (name_len != norm_len)
+ pfree(norm_name);
+
+ for (a = array, index = 0; index < dim; a++, index++)
+ {
+ /* Initcap element, assume it is normalized */
+ element_len = strlen(*a);
+ initcap_element = str_initcap(*a, element_len, collid);
+
+#ifdef DEBUG_TO_FROM_CHAR
+ elog(DEBUG_elog_output, "Name: 0x%x, Normalized: 0x%x, Element: 0x%x",
+ (unsigned char)*name, (unsigned char)*initcap_name,
+ (unsigned char)*initcap_element);
+#endif
+
+ if (strncmp(initcap_name, initcap_element, element_len) == 0)
+ {
+ *len = element_len + name_len - norm_len;
+ pfree(initcap_element);
+ pfree(initcap_name);
+ return index;
+ }
+ pfree(initcap_element);
+ }
+
+ pfree(initcap_name);
+ return -1;
+}
+
/*
* Perform a sequential search in 'array' for text matching the first 'max'
* characters of the source string.
@@ -2407,16 +2487,20 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
* If the string doesn't match, throw an error.
*/
static int
-from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max,
- FormatNode *node)
+from_char_seq_search(int *dest, char **src, const char *const *array, char **localized_array, int type, int max,
+ FormatNode *node, int dim, Oid collid)
{
int len;
- *dest = seq_search(*src, array, type, max, &len);
+ if (localized_array == NULL)
+ *dest = seq_search_sqlascii(*src, array, type, max, &len, dim);
+ else
+ *dest = seq_search_localized(*src, localized_array, max, &len, dim, collid);
if (len <= 0)
{
char copy[DCH_MAX_ITEM_SIZ + 1];
+ /* We use byte length, localized names encoding is ignored */
Assert(max <= DCH_MAX_ITEM_SIZ);
strlcpy(copy, *src, max + 1);
@@ -3017,19 +3101,24 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
* ----------
*/
static void
-DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
+DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid)
{
FormatNode *n;
char *s;
int len,
value;
bool fx_mode = false;
+ char **localized_names;
/* number of extra skipped characters (more than given in format string) */
int extra_skip = 0;
+ /* cache localized days and months */
+ cache_locale_time();
for (n = node, s = in; n->type != NODE_TYPE_END && *s != '\0'; n++)
{
+ localized_names = NULL;
+
/*
* Ignore spaces at the beginning of the string and before fields when
* not in FX (fixed width) mode.
@@ -3111,8 +3200,8 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_P_M:
case DCH_a_m:
case DCH_p_m:
- from_char_seq_search(&value, &s, ampm_strings_long,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, ampm_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(ampm_strings_long), collid);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3120,8 +3209,8 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_PM:
case DCH_am:
case DCH_pm:
- from_char_seq_search(&value, &s, ampm_strings,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, ampm_strings, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(ampm_strings), collid);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3211,30 +3300,34 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_B_C:
case DCH_a_d:
case DCH_b_c:
- from_char_seq_search(&value, &s, adbc_strings_long,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, adbc_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(adbc_strings_long), collid);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_AD:
case DCH_BC:
case DCH_ad:
case DCH_bc:
- from_char_seq_search(&value, &s, adbc_strings,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, adbc_strings, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(adbc_strings), collid);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_MONTH:
case DCH_Month:
case DCH_month:
- from_char_seq_search(&value, &s, months_full, ONE_UPPER,
- MAX_MONTH_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_months;
+ from_char_seq_search(&value, &s, months_full, localized_names,
+ ONE_UPPER, MAX_MONTH_LEN, n, lengthof(months_full), collid);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MON:
case DCH_Mon:
case DCH_mon:
- from_char_seq_search(&value, &s, months, ONE_UPPER,
- MAX_MON_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_months;
+ from_char_seq_search(&value, &s, months, localized_names,
+ ONE_UPPER, MAX_MON_LEN, n, lengthof(months_full), collid);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MM:
@@ -3244,16 +3337,20 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_DAY:
case DCH_Day:
case DCH_day:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DAY_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_days;
+ from_char_seq_search(&value, &s, days, localized_names,
+ ONE_UPPER, MAX_DAY_LEN, n, lengthof(days_short), collid);
from_char_set_int(&out->d, value, n);
out->d++;
break;
case DCH_DY:
case DCH_Dy:
case DCH_dy:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DY_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_days;
+ from_char_seq_search(&value, &s, days_short, localized_names,
+ ONE_UPPER, MAX_DY_LEN, n, lengthof(days_short), collid);
from_char_set_int(&out->d, value, n);
out->d++;
break;
@@ -3351,13 +3448,13 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
SKIP_THth(s, n->suffix);
break;
case DCH_RM:
- from_char_seq_search(&value, &s, rm_months_upper,
- ALL_UPPER, MAX_RM_LEN, n);
+ from_char_seq_search(&value, &s, rm_months_upper, localized_names,
+ ALL_UPPER, MAX_RM_LEN, n, lengthof(rm_months_upper), collid);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_rm:
- from_char_seq_search(&value, &s, rm_months_lower,
- ALL_LOWER, MAX_RM_LEN, n);
+ from_char_seq_search(&value, &s, rm_months_lower, localized_names,
+ ALL_LOWER, MAX_RM_LEN, n, lengthof(rm_months_lower), collid);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_W:
@@ -3690,7 +3787,7 @@ to_timestamp(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Use the specified time zone, if any. */
if (tm.tm_zone)
@@ -3725,7 +3822,7 @@ to_date(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Prevent overflow in Julian-day routines */
if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))
@@ -3761,7 +3858,7 @@ to_date(PG_FUNCTION_ARGS)
*/
static void
do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec)
+ struct pg_tm *tm, fsec_t *fsec, Oid collid)
{
FormatNode *format;
TmFromChar tmfc;
@@ -3810,11 +3907,11 @@ do_to_timestamp(text *date_txt, text *fmt,
}
#ifdef DEBUG_TO_FROM_CHAR
- /* dump_node(format, fmt_len); */
- /* dump_index(DCH_keywords, DCH_index); */
+ dump_node(format, fmt_len);
+ dump_index(DCH_keywords, DCH_index);
#endif
- DCH_from_char(format, date_str, &tmfc);
+ DCH_from_char(format, date_str, &tmfc, collid);
pfree(fmt_str);
if (!incache)
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index ad56ff9..5319d95 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -461,6 +461,24 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
01 NİS 2010
(1 row)
+-- to_date
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- normalized \u015E
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- not normalized \u0053+\u0327
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+ERROR: invalid value "123456789" for "MONTH"
+DETAIL: The given value did not match any of the allowed values for this field.
-- backwards parsing
CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc';
CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C";
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index eac2f90..08b0404 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -182,6 +182,14 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR");
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY');
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
+-- to_date
+
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- normalized \u015E
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- not normalized \u0053+\u0327
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+
-- backwards parsing
^ permalink raw reply [nested|flat] 325+ messages in thread
* Re: Allow to_date() and to_timestamp() to accept localized names
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-13 20:31 ` Re: Allow to_date() and to_timestamp() to accept localized names Alvaro Herrera <[email protected]>
2019-09-18 09:09 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
@ 2019-09-22 12:33 ` Juan José Santamaría Flecha <[email protected]>
2019-09-25 19:57 ` Re: Allow to_date() and to_timestamp() to accept localized names Alvaro Herrera <[email protected]>
0 siblings, 1 reply; 325+ messages in thread
From: Juan José Santamaría Flecha @ 2019-09-22 12:33 UTC (permalink / raw)
To: Alvaro Herrera <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Sep 18, 2019 at 11:09 AM Juan José Santamaría Flecha
<[email protected]> wrote:
>
> On Fri, Sep 13, 2019 at 10:31 PM Alvaro Herrera
> <[email protected]> wrote:
> >
> Thanks for taking a look at this.
>
> > I'm confused why we acquire the MONTH_DIM / etc definitions. Can't we
> > just use lengthof() of the corresponding array? AFAICS it should work
> > just as well.
> >
>
> It was because of the length difference between ascii-name arrays,
> which were all null-ended, and localized-name arrays. The attached
> version uses lengthof().
>
> > I wonder if the "compare first char" thing (seq_search_localized) really
> > works when there are multibyte chars in the day/month names. I think
> > the code compares just the first char ... but what if the original
> > string uses those funny Unicode non-normalized letters and the locale
> > translation uses normalized letters? My guess is that the first-char
> > comparison will fail, but surely you'll want the name to match.
> > (There's no month/day name in Spanish that doesn't start with an ASCII
> > letter, but I bet there are some in other languages.) I think the
> > localized comparison should avoid the first-char optimization, just
> > compare the whole string all the time, and avoid possible weird issues.
>
> The localized search is reformulated in this version to deal with
> multibyte normalization. A regression test for this issue is included.
This version is updated to optimize the need for dynamic allocation.
> Regards,
>
> Juan José Santamaría Flecha
Attachments:
[application/x-patch] 0001-Allow-localized-month-names-to_date-v3.patch (17.5K, ../../CAC+AXB2JOe4Dw1teZP-N-isNyDdY3F96oGFVYFxhmWtsbgi=ig@mail.gmail.com/2-0001-Allow-localized-month-names-to_date-v3.patch)
download | inline diff:
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 4e3e213..c470c0e 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -6415,8 +6415,17 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
<listitem>
<para>
<literal>TM</literal> does not include trailing blanks.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
<function>to_timestamp</function> and <function>to_date</function> ignore
- the <literal>TM</literal> modifier.
+ the case when receiving names as an input. For example, either
+ <literal>to_timestamp('2000-JUN', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-Jun', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-JUN', 'YYYY-mon')</literal> work and return
+ the same output.
</para>
</listitem>
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 755ca6e..39d2d11 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -96,6 +96,7 @@
#include "utils/memutils.h"
#include "utils/numeric.h"
#include "utils/pg_locale.h"
+#include "common/unicode_norm.h"
/* ----------
* Routines type
@@ -174,18 +175,17 @@ typedef struct
#define CLOCK_24_HOUR 0
#define CLOCK_12_HOUR 1
-
/* ----------
* Full months
* ----------
*/
static const char *const months_full[] = {
"January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December", NULL
+ "August", "September", "October", "November", "December"
};
static const char *const days_short[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
/* ----------
@@ -217,8 +217,8 @@ static const char *const days_short[] = {
* matches for BC have an odd index. So the boolean value for BC is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR, NULL};
-static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR, NULL};
+static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR};
+static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR};
/* ----------
* AM / PM
@@ -244,8 +244,8 @@ static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_S
* matches for PM have an odd index. So the boolean value for PM is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR, NULL};
-static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR, NULL};
+static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR};
+static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR};
/* ----------
* Months in roman-numeral
@@ -254,10 +254,10 @@ static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_S
* ----------
*/
static const char *const rm_months_upper[] =
-{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I", NULL};
+{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I"};
static const char *const rm_months_lower[] =
-{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i", NULL};
+{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i"};
/* ----------
* Roman numbers
@@ -975,7 +975,7 @@ static void parse_format(FormatNode *node, const char *str, const KeyWord *kw,
static void DCH_to_char(FormatNode *node, bool is_interval,
TmToChar *in, char *out, Oid collid);
-static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out);
+static void DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid);
#ifdef DEBUG_TO_FROM_CHAR
static void dump_index(const KeyWord *k, const int *index);
@@ -990,10 +990,12 @@ static void from_char_set_mode(TmFromChar *tmfc, const FromCharDateMode mode);
static void from_char_set_int(int *dest, const int value, const FormatNode *node);
static int from_char_parse_int_len(int *dest, char **src, const int len, FormatNode *node);
static int from_char_parse_int(int *dest, char **src, FormatNode *node);
-static int seq_search(char *name, const char *const *array, int type, int max, int *len);
-static int from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max, FormatNode *node);
+static int seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim);
+static int seq_search_localized(char *name, char **array, int max, int *len, int dim, Oid collid);
+static int from_char_seq_search(int *dest, char **src, const char *const *array, char **localized_array, int type, int max,
+ FormatNode *node, int dim, Oid collid);
static void do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec);
+ struct pg_tm *tm, fsec_t *fsec, Oid collid);
static char *fill_str(char *str, int c, int max);
static FormatNode *NUM_cache(int len, NUMDesc *Num, text *pars_str, bool *shouldFree);
static char *int_to_roman(int number);
@@ -2325,17 +2327,18 @@ from_char_parse_int(int *dest, char **src, FormatNode *node)
}
/* ----------
- * Sequential search with to upper/lower conversion
+ * Sequential search with to upper/lower conversion for SQL_ASCII array input
* ----------
*/
static int
-seq_search(char *name, const char *const *array, int type, int max, int *len)
+seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim)
{
const char *p;
const char *const *a;
char *n;
int last,
i;
+ int index;
*len = 0;
@@ -2348,7 +2351,7 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
else if (type == ALL_LOWER)
*name = pg_tolower((unsigned char) *name);
- for (last = 0, a = array; *a != NULL; a++)
+ for (last = 0, a = array, index = 0; index < dim; a++, index++)
{
/* compare first chars */
if (*name != **a)
@@ -2360,13 +2363,13 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
if (max && i == max)
{
*len = i;
- return a - array;
+ return index;
}
/* full size */
if (*p == '\0')
{
*len = i;
- return a - array;
+ return index;
}
/* Not found in array 'a' */
if (*n == '\0')
@@ -2396,6 +2399,83 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
return -1;
}
+/* ----------
+ * Sequential search with initcap conversion for localized array input
+ * ----------
+ */
+static int
+seq_search_localized(char *name, char **array, int max, int *len, int dim, Oid collid)
+{
+ char **a;
+ char *initcap_element;
+ char *initcap_name;
+ char *norm_name;
+ int index;
+ int mb_max;
+ int name_len;
+ int encoding;
+ int norm_len;
+ int element_len;
+
+ *len = 0;
+
+ if (!*name)
+ return -1;
+
+ encoding = GetDatabaseEncoding();
+ mb_max = max * pg_encoding_max_length(encoding);
+ name_len = strlen(name);
+ name_len = name_len < mb_max ? name_len : mb_max;
+
+ /* Normalize and initcap name */
+ norm_name = name;
+ norm_len = name_len;
+ if (mb_max > max && encoding == PG_UTF8)
+ {
+ pg_wchar *wchar_name;
+ pg_wchar *norm_wname;
+ size_t name_wlen;
+ size_t norm_wlen;
+ wchar_name = (pg_wchar *) palloc((name_len + 1) * sizeof(pg_wchar));
+ name_wlen = pg_mb2wchar_with_len(name, wchar_name, name_len);
+ norm_wname = unicode_normalize_kc(wchar_name);
+ pfree(wchar_name);
+ norm_wlen = pg_wchar_strlen(norm_wname);
+ if (name_wlen > norm_wlen)
+ {
+ norm_name = (char *) palloc((norm_wlen + 1) * sizeof(pg_wchar));
+ norm_len = pg_wchar2mb_with_len(norm_wname, norm_name, norm_wlen);
+ }
+ pfree(norm_wname);
+ }
+ initcap_name = str_initcap(norm_name, norm_len, collid);
+ if (name_len != norm_len)
+ pfree(norm_name);
+
+ for (a = array, index = 0; index < dim; a++, index++)
+ {
+ /* Initcap element, assume it is normalized */
+ element_len = strlen(*a);
+ initcap_element = str_initcap(*a, element_len, collid);
+
+#ifdef DEBUG_TO_FROM_CHAR
+ elog(DEBUG_elog_output, "Name: 0x%x, Normalized: 0x%x, Element: 0x%x",
+ (unsigned char)*name, (unsigned char)*initcap_name, (unsigned char)*initcap_element);
+#endif
+ if (strncmp(initcap_name, initcap_element, element_len) == 0)
+ {
+ *len = element_len + name_len - norm_len;
+ pfree(initcap_element);
+ pfree(initcap_name);
+ return index;
+ }
+ pfree(initcap_element);
+ }
+
+ pfree(initcap_name);
+ return -1;
+}
+
/*
* Perform a sequential search in 'array' for text matching the first 'max'
* characters of the source string.
@@ -2407,16 +2487,20 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
* If the string doesn't match, throw an error.
*/
static int
-from_char_seq_search(int *dest, char **src, const char *const *array, int type, int max,
- FormatNode *node)
+from_char_seq_search(int *dest, char **src, const char *const *array, char **localized_array, int type, int max,
+ FormatNode *node, int dim, Oid collid)
{
int len;
- *dest = seq_search(*src, array, type, max, &len);
+ if (localized_array == NULL)
+ *dest = seq_search_sqlascii(*src, array, type, max, &len, dim);
+ else
+ *dest = seq_search_localized(*src, localized_array, max, &len, dim, collid);
if (len <= 0)
{
char copy[DCH_MAX_ITEM_SIZ + 1];
+ /* We use byte length, localized names encoding is ignored */
Assert(max <= DCH_MAX_ITEM_SIZ);
strlcpy(copy, *src, max + 1);
@@ -3017,19 +3101,24 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
* ----------
*/
static void
-DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
+DCH_from_char(FormatNode *node, char *in, TmFromChar *out, Oid collid)
{
FormatNode *n;
char *s;
int len,
value;
bool fx_mode = false;
+ char **localized_names;
/* number of extra skipped characters (more than given in format string) */
int extra_skip = 0;
+ /* cache localized days and months */
+ cache_locale_time();
for (n = node, s = in; n->type != NODE_TYPE_END && *s != '\0'; n++)
{
+ localized_names = NULL;
+
/*
* Ignore spaces at the beginning of the string and before fields when
* not in FX (fixed width) mode.
@@ -3111,8 +3200,8 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_P_M:
case DCH_a_m:
case DCH_p_m:
- from_char_seq_search(&value, &s, ampm_strings_long,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, ampm_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(ampm_strings_long), collid);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3120,8 +3209,8 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_PM:
case DCH_am:
case DCH_pm:
- from_char_seq_search(&value, &s, ampm_strings,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, ampm_strings, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(ampm_strings), collid);
from_char_set_int(&out->pm, value % 2, n);
out->clock = CLOCK_12_HOUR;
break;
@@ -3211,30 +3300,34 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_B_C:
case DCH_a_d:
case DCH_b_c:
- from_char_seq_search(&value, &s, adbc_strings_long,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, adbc_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(adbc_strings_long), collid);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_AD:
case DCH_BC:
case DCH_ad:
case DCH_bc:
- from_char_seq_search(&value, &s, adbc_strings,
- ALL_UPPER, n->key->len, n);
+ from_char_seq_search(&value, &s, adbc_strings, localized_names,
+ ALL_UPPER, n->key->len, n, lengthof(adbc_strings), collid);
from_char_set_int(&out->bc, value % 2, n);
break;
case DCH_MONTH:
case DCH_Month:
case DCH_month:
- from_char_seq_search(&value, &s, months_full, ONE_UPPER,
- MAX_MONTH_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_months;
+ from_char_seq_search(&value, &s, months_full, localized_names,
+ ONE_UPPER, MAX_MONTH_LEN, n, lengthof(months_full), collid);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MON:
case DCH_Mon:
case DCH_mon:
- from_char_seq_search(&value, &s, months, ONE_UPPER,
- MAX_MON_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_months;
+ from_char_seq_search(&value, &s, months, localized_names,
+ ONE_UPPER, MAX_MON_LEN, n, lengthof(months_full), collid);
from_char_set_int(&out->mm, value + 1, n);
break;
case DCH_MM:
@@ -3244,16 +3337,20 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
case DCH_DAY:
case DCH_Day:
case DCH_day:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DAY_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_days;
+ from_char_seq_search(&value, &s, days, localized_names,
+ ONE_UPPER, MAX_DAY_LEN, n, lengthof(days_short), collid);
from_char_set_int(&out->d, value, n);
out->d++;
break;
case DCH_DY:
case DCH_Dy:
case DCH_dy:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DY_LEN, n);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_days;
+ from_char_seq_search(&value, &s, days_short, localized_names,
+ ONE_UPPER, MAX_DY_LEN, n, lengthof(days_short), collid);
from_char_set_int(&out->d, value, n);
out->d++;
break;
@@ -3351,13 +3448,13 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out)
SKIP_THth(s, n->suffix);
break;
case DCH_RM:
- from_char_seq_search(&value, &s, rm_months_upper,
- ALL_UPPER, MAX_RM_LEN, n);
+ from_char_seq_search(&value, &s, rm_months_upper, localized_names,
+ ALL_UPPER, MAX_RM_LEN, n, lengthof(rm_months_upper), collid);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_rm:
- from_char_seq_search(&value, &s, rm_months_lower,
- ALL_LOWER, MAX_RM_LEN, n);
+ from_char_seq_search(&value, &s, rm_months_lower, localized_names,
+ ALL_LOWER, MAX_RM_LEN, n, lengthof(rm_months_lower), collid);
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value, n);
break;
case DCH_W:
@@ -3690,7 +3787,7 @@ to_timestamp(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Use the specified time zone, if any. */
if (tm.tm_zone)
@@ -3725,7 +3822,7 @@ to_date(PG_FUNCTION_ARGS)
struct pg_tm tm;
fsec_t fsec;
- do_to_timestamp(date_txt, fmt, &tm, &fsec);
+ do_to_timestamp(date_txt, fmt, &tm, &fsec, PG_GET_COLLATION());
/* Prevent overflow in Julian-day routines */
if (!IS_VALID_JULIAN(tm.tm_year, tm.tm_mon, tm.tm_mday))
@@ -3761,7 +3858,7 @@ to_date(PG_FUNCTION_ARGS)
*/
static void
do_to_timestamp(text *date_txt, text *fmt,
- struct pg_tm *tm, fsec_t *fsec)
+ struct pg_tm *tm, fsec_t *fsec, Oid collid)
{
FormatNode *format;
TmFromChar tmfc;
@@ -3810,11 +3907,11 @@ do_to_timestamp(text *date_txt, text *fmt,
}
#ifdef DEBUG_TO_FROM_CHAR
- /* dump_node(format, fmt_len); */
- /* dump_index(DCH_keywords, DCH_index); */
+ dump_node(format, fmt_len);
+ dump_index(DCH_keywords, DCH_index);
#endif
- DCH_from_char(format, date_str, &tmfc);
+ DCH_from_char(format, date_str, &tmfc, collid);
pfree(fmt_str);
if (!incache)
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index ad56ff9..5319d95 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -461,6 +461,24 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
01 NİS 2010
(1 row)
+-- to_date
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- normalized \u015E
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- not normalized \u0053+\u0327
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+ERROR: invalid value "123456789" for "MONTH"
+DETAIL: The given value did not match any of the allowed values for this field.
-- backwards parsing
CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc';
CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C";
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index eac2f90..08b0404 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -182,6 +182,14 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR");
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY');
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
+-- to_date
+
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- normalized \u015E
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- not normalized \u0053+\u0327
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+
-- backwards parsing
^ permalink raw reply [nested|flat] 325+ messages in thread
* Re: Allow to_date() and to_timestamp() to accept localized names
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-13 20:31 ` Re: Allow to_date() and to_timestamp() to accept localized names Alvaro Herrera <[email protected]>
2019-09-18 09:09 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-22 12:33 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
@ 2019-09-25 19:57 ` Alvaro Herrera <[email protected]>
2019-09-26 18:36 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
0 siblings, 1 reply; 325+ messages in thread
From: Alvaro Herrera @ 2019-09-25 19:57 UTC (permalink / raw)
To: Juan José Santamaría Flecha <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
This patch no longer applies. Can you please rebase?
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 325+ messages in thread
* Re: Allow to_date() and to_timestamp() to accept localized names
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-13 20:31 ` Re: Allow to_date() and to_timestamp() to accept localized names Alvaro Herrera <[email protected]>
2019-09-18 09:09 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-22 12:33 ` Re: Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-09-25 19:57 ` Re: Allow to_date() and to_timestamp() to accept localized names Alvaro Herrera <[email protected]>
@ 2019-09-26 18:36 ` Juan José Santamaría Flecha <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Juan José Santamaría Flecha @ 2019-09-26 18:36 UTC (permalink / raw)
To: Alvaro Herrera <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Sep 25, 2019 at 9:57 PM Alvaro Herrera <[email protected]> wrote:
>
> This patch no longer applies. Can you please rebase?
Thank you for the notification.
The patch rot after commit 1a950f3, a rebased version is attached.
Regards,
Juan José Santamaría Flecha
Attachments:
[application/x-patch] 0001-Allow-localized-month-names-to_date-v4.patch (16.6K, ../../CAC+AXB12A7Fr9djoq7f1-WYesnZTRKpGpHM12MRG+M00mewN9g@mail.gmail.com/2-0001-Allow-localized-month-names-to_date-v4.patch)
download | inline diff:
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 67f1a82..bf9055e 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -6578,8 +6578,17 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}');
<listitem>
<para>
<literal>TM</literal> does not include trailing blanks.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
<function>to_timestamp</function> and <function>to_date</function> ignore
- the <literal>TM</literal> modifier.
+ the case when receiving names as an input. For example, either
+ <literal>to_timestamp('2000-JUN', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-Jun', 'YYYY-MON')</literal> or
+ <literal>to_timestamp('2000-JUN', 'YYYY-mon')</literal> work and return
+ the same output
</para>
</listitem>
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index f7175df..d69d89a 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -97,6 +97,7 @@
#include "utils/memutils.h"
#include "utils/numeric.h"
#include "utils/pg_locale.h"
+#include "common/unicode_norm.h"
/* ----------
* Convenience macros for error handling
@@ -220,11 +221,11 @@ typedef struct
*/
static const char *const months_full[] = {
"January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December", NULL
+ "August", "September", "October", "November", "December"
};
static const char *const days_short[] = {
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
/* ----------
@@ -256,8 +257,8 @@ static const char *const days_short[] = {
* matches for BC have an odd index. So the boolean value for BC is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR, NULL};
-static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR, NULL};
+static const char *const adbc_strings[] = {ad_STR, bc_STR, AD_STR, BC_STR};
+static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_STR};
/* ----------
* AM / PM
@@ -283,8 +284,8 @@ static const char *const adbc_strings_long[] = {a_d_STR, b_c_STR, A_D_STR, B_C_S
* matches for PM have an odd index. So the boolean value for PM is given by
* taking the array index of the match, modulo 2.
*/
-static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR, NULL};
-static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR, NULL};
+static const char *const ampm_strings[] = {am_STR, pm_STR, AM_STR, PM_STR};
+static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_STR};
/* ----------
* Months in roman-numeral
@@ -293,10 +294,10 @@ static const char *const ampm_strings_long[] = {a_m_STR, p_m_STR, A_M_STR, P_M_S
* ----------
*/
static const char *const rm_months_upper[] =
-{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I", NULL};
+{"XII", "XI", "X", "IX", "VIII", "VII", "VI", "V", "IV", "III", "II", "I"};
static const char *const rm_months_lower[] =
-{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i", NULL};
+{"xii", "xi", "x", "ix", "viii", "vii", "vi", "v", "iv", "iii", "ii", "i"};
/* ----------
* Roman numbers
@@ -1068,10 +1069,11 @@ static int from_char_parse_int_len(int *dest, char **src, const int len,
FormatNode *node, bool *have_error);
static int from_char_parse_int(int *dest, char **src, FormatNode *node,
bool *have_error);
-static int seq_search(char *name, const char *const *array, int type, int max, int *len);
+static int seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim);
+static int seq_search_localized(char *name, char **array, int max, int *len, int dim);
static int from_char_seq_search(int *dest, char **src,
- const char *const *array, int type, int max,
- FormatNode *node, bool *have_error);
+ const char *const *array, char **localized_array, int type, int max,
+ FormatNode *node, bool *have_error, int dim);
static void do_to_timestamp(text *date_txt, text *fmt, bool std,
struct pg_tm *tm, fsec_t *fsec, int *fprec,
uint32 *flags, bool *have_error);
@@ -2454,17 +2456,18 @@ from_char_parse_int(int *dest, char **src, FormatNode *node, bool *have_error)
}
/* ----------
- * Sequential search with to upper/lower conversion
+ * Sequential search with to upper/lower conversion for SQL_ASCII array input
* ----------
*/
static int
-seq_search(char *name, const char *const *array, int type, int max, int *len)
+seq_search_sqlascii(char *name, const char *const *array, int type, int max, int *len, int dim)
{
const char *p;
const char *const *a;
char *n;
int last,
i;
+ int index;
*len = 0;
@@ -2477,7 +2480,7 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
else if (type == ALL_LOWER)
*name = pg_tolower((unsigned char) *name);
- for (last = 0, a = array; *a != NULL; a++)
+ for (last = 0, a = array, index = 0; index < dim; a++, index++)
{
/* compare first chars */
if (*name != **a)
@@ -2489,13 +2492,13 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
if (max && i == max)
{
*len = i;
- return a - array;
+ return index;
}
/* full size */
if (*p == '\0')
{
*len = i;
- return a - array;
+ return index;
}
/* Not found in array 'a' */
if (*n == '\0')
@@ -2525,6 +2528,84 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
return -1;
}
+/* ----------
+ * Sequential search with initcap conversion for localized array input
+ * ----------
+ */
+static int
+seq_search_localized(char *name, char **array, int max, int *len, int dim)
+{
+ char **a;
+ char *initcap_element;
+ char *initcap_name;
+ char *norm_name;
+ int index;
+ int mb_max;
+ int name_len;
+ int encoding;
+ int norm_len;
+ int element_len;
+
+ *len = 0;
+
+ if (!*name)
+ return -1;
+
+ encoding = GetDatabaseEncoding();
+ mb_max = max * pg_encoding_max_length(encoding);
+ name_len = strlen(name);
+ name_len = name_len < mb_max ? name_len : mb_max;
+ norm_name = name;
+ norm_len = name_len;
+
+ /* Normalize and initcap name */
+ if (mb_max > max && encoding == PG_UTF8)
+ {
+ pg_wchar *wchar_name;
+ pg_wchar *norm_wname;
+ size_t name_wlen;
+ size_t norm_wlen;
+
+ wchar_name = (pg_wchar *) palloc((name_len + 1) * sizeof(pg_wchar));
+ name_wlen = pg_mb2wchar_with_len(name, wchar_name, name_len);
+ norm_wname = unicode_normalize_kc(wchar_name);
+ pfree(wchar_name);
+ norm_wlen = pg_wchar_strlen(norm_wname);
+ if (name_wlen > norm_wlen)
+ {
+ norm_name = (char *) palloc((norm_wlen + 1) * sizeof(pg_wchar));
+ norm_len = pg_wchar2mb_with_len(norm_wname, norm_name, norm_wlen);
+ }
+ pfree(norm_wname);
+ }
+ initcap_name = str_initcap(norm_name, norm_len, DEFAULT_COLLATION_OID);
+ if (name_len != norm_len)
+ pfree(norm_name);
+
+ for (a = array, index = 0; index < dim; a++, index++)
+ {
+ /* Initcap element, assume it is normalized */
+ element_len = strlen(*a);
+ initcap_element = str_initcap(*a, element_len, DEFAULT_COLLATION_OID);
+
+#ifdef DEBUG_TO_FROM_CHAR
+ elog(DEBUG_elog_output, "Name: 0x%x, Normalized: 0x%x, Element: 0x%x",
+ (unsigned char)*name, (unsigned char)*initcap_name, (unsigned char)*initcap_element);
+#endif
+ if (strncmp(initcap_name, initcap_element, element_len) == 0)
+ {
+ *len = element_len + name_len - norm_len;
+ pfree(initcap_element);
+ pfree(initcap_name);
+ return index;
+ }
+ pfree(initcap_element);
+ }
+
+ pfree(initcap_name);
+ return -1;
+}
+
/*
* Perform a sequential search in 'array' for text matching the first 'max'
* characters of the source string.
@@ -2537,16 +2618,20 @@ seq_search(char *name, const char *const *array, int type, int max, int *len)
* otherwise set '*have_error' and return -1.
*/
static int
-from_char_seq_search(int *dest, char **src, const char *const *array, int type,
- int max, FormatNode *node, bool *have_error)
+from_char_seq_search(int *dest, char **src, const char *const *array, char **localized_array,
+ int type, int max, FormatNode *node, bool *have_error, int dim)
{
int len;
- *dest = seq_search(*src, array, type, max, &len);
+ if (localized_array == NULL)
+ *dest = seq_search_sqlascii(*src, array, type, max, &len, dim);
+ else
+ *dest = seq_search_localized(*src, localized_array, max, &len, dim);
if (len <= 0)
{
char copy[DCH_MAX_ITEM_SIZ + 1];
+ /* We use byte length, localized names encoding is ignored */
Assert(max <= DCH_MAX_ITEM_SIZ);
strlcpy(copy, *src, max + 1);
@@ -3174,12 +3259,16 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
int len,
value;
bool fx_mode = std;
+ char **localized_names;
/* number of extra skipped characters (more than given in format string) */
int extra_skip = 0;
+ /* cache localized days and months */
+ cache_locale_time();
for (n = node, s = in; n->type != NODE_TYPE_END && *s != '\0'; n++)
{
+ localized_names = NULL;
/*
* Ignore spaces at the beginning of the string and before fields when
* not in FX (fixed width) mode.
@@ -3278,8 +3367,9 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_P_M:
case DCH_a_m:
case DCH_p_m:
- from_char_seq_search(&value, &s, ampm_strings_long,
- ALL_UPPER, n->key->len, n, have_error);
+ from_char_seq_search(&value, &s, ampm_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, have_error,
+ lengthof(ampm_strings_long));
CHECK_ERROR;
from_char_set_int(&out->pm, value % 2, n, have_error);
CHECK_ERROR;
@@ -3289,8 +3379,9 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_PM:
case DCH_am:
case DCH_pm:
- from_char_seq_search(&value, &s, ampm_strings,
- ALL_UPPER, n->key->len, n, have_error);
+ from_char_seq_search(&value, &s, ampm_strings, localized_names,
+ ALL_UPPER, n->key->len, n, have_error,
+ lengthof(ampm_strings));
CHECK_ERROR;
from_char_set_int(&out->pm, value % 2, n, have_error);
CHECK_ERROR;
@@ -3402,8 +3493,9 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_B_C:
case DCH_a_d:
case DCH_b_c:
- from_char_seq_search(&value, &s, adbc_strings_long,
- ALL_UPPER, n->key->len, n, have_error);
+ from_char_seq_search(&value, &s, adbc_strings_long, localized_names,
+ ALL_UPPER, n->key->len, n, have_error,
+ lengthof(adbc_strings_long));
CHECK_ERROR;
from_char_set_int(&out->bc, value % 2, n, have_error);
CHECK_ERROR;
@@ -3412,8 +3504,9 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_BC:
case DCH_ad:
case DCH_bc:
- from_char_seq_search(&value, &s, adbc_strings,
- ALL_UPPER, n->key->len, n, have_error);
+ from_char_seq_search(&value, &s, adbc_strings, localized_names,
+ ALL_UPPER, n->key->len, n, have_error,
+ lengthof(adbc_strings));
CHECK_ERROR;
from_char_set_int(&out->bc, value % 2, n, have_error);
CHECK_ERROR;
@@ -3421,8 +3514,11 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_MONTH:
case DCH_Month:
case DCH_month:
- from_char_seq_search(&value, &s, months_full, ONE_UPPER,
- MAX_MONTH_LEN, n, have_error);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_months;
+ from_char_seq_search(&value, &s, months_full, localized_names,
+ ONE_UPPER, MAX_MONTH_LEN, n, have_error,
+ lengthof(months_full));
CHECK_ERROR;
from_char_set_int(&out->mm, value + 1, n, have_error);
CHECK_ERROR;
@@ -3430,8 +3526,11 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_MON:
case DCH_Mon:
case DCH_mon:
- from_char_seq_search(&value, &s, months, ONE_UPPER,
- MAX_MON_LEN, n, have_error);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_months;
+ from_char_seq_search(&value, &s, months, localized_names,
+ ONE_UPPER, MAX_MON_LEN, n, have_error,
+ lengthof(months_full));
CHECK_ERROR;
from_char_set_int(&out->mm, value + 1, n, have_error);
CHECK_ERROR;
@@ -3444,8 +3543,11 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_DAY:
case DCH_Day:
case DCH_day:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DAY_LEN, n, have_error);
+ if (S_TM(n->suffix))
+ localized_names = localized_full_days;
+ from_char_seq_search(&value, &s, days, localized_names,
+ ONE_UPPER, MAX_DAY_LEN, n, have_error,
+ lengthof(days_short));
CHECK_ERROR;
from_char_set_int(&out->d, value, n, have_error);
CHECK_ERROR;
@@ -3454,8 +3556,11 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
case DCH_DY:
case DCH_Dy:
case DCH_dy:
- from_char_seq_search(&value, &s, days, ONE_UPPER,
- MAX_DY_LEN, n, have_error);
+ if (S_TM(n->suffix))
+ localized_names = localized_abbrev_days;
+ from_char_seq_search(&value, &s, days_short, localized_names,
+ ONE_UPPER, MAX_DY_LEN, n, have_error,
+ lengthof(days_short));
CHECK_ERROR;
from_char_set_int(&out->d, value, n, have_error);
CHECK_ERROR;
@@ -3571,16 +3676,18 @@ DCH_from_char(FormatNode *node, char *in, TmFromChar *out, bool std,
SKIP_THth(s, n->suffix);
break;
case DCH_RM:
- from_char_seq_search(&value, &s, rm_months_upper,
- ALL_UPPER, MAX_RM_LEN, n, have_error);
+ from_char_seq_search(&value, &s, rm_months_upper, localized_names,
+ ALL_UPPER, MAX_RM_LEN, n, have_error,
+ lengthof(rm_months_upper));
CHECK_ERROR;
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value,
n, have_error);
CHECK_ERROR;
break;
case DCH_rm:
- from_char_seq_search(&value, &s, rm_months_lower,
- ALL_LOWER, MAX_RM_LEN, n, have_error);
+ from_char_seq_search(&value, &s, rm_months_lower, localized_names,
+ ALL_LOWER, MAX_RM_LEN, n, have_error,
+ lengthof(rm_months_lower));
CHECK_ERROR;
from_char_set_int(&out->mm, MONTHS_PER_YEAR - value,
n, have_error);
@@ -4356,8 +4463,8 @@ do_to_timestamp(text *date_txt, text *fmt, bool std,
}
#ifdef DEBUG_TO_FROM_CHAR
- /* dump_node(format, fmt_len); */
- /* dump_index(DCH_keywords, DCH_index); */
+ dump_node(format, fmt_len);
+ dump_index(DCH_keywords, DCH_index);
#endif
DCH_from_char(format, date_str, &tmfc, std, have_error);
diff --git a/src/test/regress/expected/collate.linux.utf8.out b/src/test/regress/expected/collate.linux.utf8.out
index ad56ff9..5319d95 100644
--- a/src/test/regress/expected/collate.linux.utf8.out
+++ b/src/test/regress/expected/collate.linux.utf8.out
@@ -461,6 +461,24 @@ SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
01 NİS 2010
(1 row)
+-- to_date
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- normalized \u015E
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- not normalized \u0053+\u0327
+ to_timestamp
+------------------------
+ 2010-02-01 00:00:00+00
+(1 row)
+
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+ERROR: invalid value "123456789" for "MONTH"
+DETAIL: The given value did not match any of the allowed values for this field.
-- backwards parsing
CREATE VIEW collview1 AS SELECT * FROM collate_test1 WHERE b COLLATE "C" >= 'bbc';
CREATE VIEW collview2 AS SELECT a, b FROM collate_test1 ORDER BY b COLLATE "C";
diff --git a/src/test/regress/sql/collate.linux.utf8.sql b/src/test/regress/sql/collate.linux.utf8.sql
index eac2f90..08b0404 100644
--- a/src/test/regress/sql/collate.linux.utf8.sql
+++ b/src/test/regress/sql/collate.linux.utf8.sql
@@ -182,6 +182,14 @@ SELECT to_char(date '2010-02-01', 'DD TMMON YYYY' COLLATE "tr_TR");
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY');
SELECT to_char(date '2010-04-01', 'DD TMMON YYYY' COLLATE "tr_TR");
+-- to_date
+
+SET DateStyle='ISO, YMD';
+SET TimeZone='UTC';
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- normalized \u015E
+SELECT to_timestamp('01 ŞUB 2010', 'DD TMMON YYYY'); -- not normalized \u0053+\u0327
+SELECT to_timestamp('1234567890ab 2010', 'TMMONTH YYYY'); -- fail
+
-- backwards parsing
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal
@ 2025-08-04 22:05 Erik Wienhold <[email protected]>
0 siblings, 0 replies; 325+ messages in thread
From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw)
Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED
VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner
that way in my opinion by not having to resolve the tablespace name just
to pass it to AlterTableInternal. The default table space is passed as
empty string to AlterTableInternal.
---
src/backend/commands/createas.c | 21 ++-------------------
src/backend/commands/tablecmds.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c
index 1620273f965..30ca0a21903 100644
--- a/src/backend/commands/createas.c
+++ b/src/backend/commands/createas.c
@@ -24,7 +24,6 @@
*/
#include "postgres.h"
-#include "miscadmin.h"
#include "access/heapam.h"
#include "access/reloptions.h"
#include "access/tableam.h"
@@ -35,7 +34,6 @@
#include "commands/matview.h"
#include "commands/prepare.h"
#include "commands/tablecmds.h"
-#include "commands/tablespace.h"
#include "commands/view.h"
#include "executor/execdesc.h"
#include "executor/executor.h"
@@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into)
/* tablespace */
atcmd = makeNode(AlterTableCmd);
atcmd->subtype = AT_SetTableSpace;
- if (into->tableSpaceName != NULL)
- atcmd->name = into->tableSpaceName;
- else
- {
- Oid spcid;
-
- /*
- * Resolve the name of the default or database tablespace because
- * we need to specify the tablespace by name.
- *
- * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then.
- */
- spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false);
- if (!OidIsValid(spcid))
- spcid = MyDatabaseTableSpace;
- atcmd->name = get_tablespace_name(spcid);
- }
+ /* use empty string to specify default tablespace */
+ atcmd->name = into->tableSpaceName ? into->tableSpaceName : "";
atcmds = lappend(atcmds, atcmd);
/* storage options */
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 44dcd2c5b0d..6ec0b87f841 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen
{
Oid tablespaceId;
- /* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename, false);
+ if (tablespacename != NULL && tablespacename[0] == '\0')
+ {
+ /* Use default tablespace if name is empty string */
+ tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition);
+ if (!OidIsValid(tablespaceId))
+ tablespaceId = MyDatabaseTableSpace;
+ }
+ else
+ {
+ /* Check that the tablespace exists */
+ tablespaceId = get_tablespace_oid(tablespacename, false);
+ }
/* Check permissions except when moving to database's default */
if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace)
--
2.50.1
--r33ycpluvyfavkwy
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch"
^ permalink raw reply [nested|flat] 325+ messages in thread
end of thread, other threads:[~2025-08-04 22:05 UTC | newest]
Thread overview: 325+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-18 08:42 Allow to_date() and to_timestamp() to accept localized names Juan José Santamaría Flecha <[email protected]>
2019-08-22 19:38 ` Juan José Santamaría Flecha <[email protected]>
2019-08-23 08:33 ` Juan José Santamaría Flecha <[email protected]>
2019-09-13 20:31 ` Alvaro Herrera <[email protected]>
2019-09-18 09:09 ` Juan José Santamaría Flecha <[email protected]>
2019-09-22 12:33 ` Juan José Santamaría Flecha <[email protected]>
2019-09-25 19:57 ` Alvaro Herrera <[email protected]>
2019-09-26 18:36 ` Juan José Santamaría Flecha <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox