agora inbox for [email protected]help / color / mirror / Atom feed
Windows Vista support (Buildfarm Vaquita) 333+ messages / 7 participants [nested] [flat]
* Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 08:21 Dave Page <[email protected]> 0 siblings, 1 reply; 333+ messages in thread From: Dave Page @ 2007-05-09 08:21 UTC (permalink / raw) To: pgsql-hackers Hi, I asked about this before, but the thread got hijacked to discuss another buildfarm failure :-(. Currently our only Windows Vista buildfarm member (Vaquita) fails every time (assuming it gets that far) on ECPG's dt_test and update tests. I've checked the FS permissions, and see no obvious reason why the tests would fail, and I've tried running the tests manually and see them fail as well. Can someone suggest what I might try next to resolve this? I don't really have the spare time to spend figuring out ECPG at the moment. http://www.pgbuildfarm.org/cgi-bin/show_log.pl?nm=vaquita&dt=2007-05-07%2020:00:05 Regards, Dave. ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 09:01 Michael Meskes <[email protected]> parent: Dave Page <[email protected]> 0 siblings, 1 reply; 333+ messages in thread From: Michael Meskes @ 2007-05-09 09:01 UTC (permalink / raw) To: Dave Page <[email protected]>; +Cc: pgsql-hackers On Wed, May 09, 2007 at 09:21:59AM +0100, Dave Page wrote: > I asked about this before, but the thread got hijacked to discuss > another buildfarm failure :-(. Currently our only Windows Vista > buildfarm member (Vaquita) fails every time (assuming it gets that far) > on ECPG's dt_test and update tests. Dave, could you please run insert into date_test ( d , ts ) values ( date '1966-01-17' , timestamp '2000-07-12 17:34:29' ); on the Vista system and then select * from date_test;? According to the logs the insert runs successfully but the select gives an invalid date format. Interestingly the date argument is displayed correctly but the timestamp argument throws the invalid date error, which does not really make sense. Unfortunately I do not have access to a Vista system I could use to test and track this one down. As far as the other message is concerned I'm at a loss. It simply refuses to run the sql/update script. No idea why. Michael -- Michael Meskes Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org) ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: [email protected] Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL! ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 11:46 Dave Page <[email protected]> parent: Michael Meskes <[email protected]> 0 siblings, 4 replies; 333+ messages in thread From: Dave Page @ 2007-05-09 11:46 UTC (permalink / raw) To: [email protected]; pgsql-hackers Michael Meskes wrote: > Dave, could you please run > > insert into date_test ( d , ts ) values ( date '1966-01-17' , > timestamp '2000-07-12 17:34:29' ); > > on the Vista system and then select * from date_test;? > > According to the logs the insert runs successfully but the select gives > an invalid date format. Interestingly the date argument is displayed > correctly but the timestamp argument throws the invalid date error, > which does not really make sense. I had to create the table manually of course, so copying what the code seems to do, I get: regress1=# create table date_test (d date, ts timestamp); CREATE TABLE regress1=# set datestyle to iso; SET regress1=# insert into date_test(d, ts) values (date '1966-01-17', timestamp '2000-07-12 17:34:29'); INSERT 0 1 regress1=# select * from date_test; d | ts ------------+--------------------- 1966-01-17 | 2000-07-12 17:34:29 (1 row) Which looks OK to me :-( > Unfortunately I do not have access to a Vista system I could use to test > and track this one down. I'm happy to run any tests you like. > As far as the other message is concerned I'm at a loss. It simply > refuses to run the sql/update script. No idea why. Oh, hang on... Vista's new 'security' features include popups that ask permission from the user before running any installers. One of the more basic checks they use is the filename - *anything* called setup.exe will cause user confirmation to be required before it will run. I believe for non-interactive sessions it'll just refuse to run. I just tried running update.exe myself, and yes, you guessed it, a user confirmation dialog popped up :-( Can we rename the test please? Regards, Dave. ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 12:20 Peter Eisentraut <[email protected]> parent: Dave Page <[email protected]> 3 siblings, 2 replies; 333+ messages in thread From: Peter Eisentraut @ 2007-05-09 12:20 UTC (permalink / raw) To: pgsql-hackers; +Cc: Dave Page <[email protected]>; [email protected] Am Mittwoch, 9. Mai 2007 13:46 schrieb Dave Page: > Can we rename the test please? I'm thinking no. Brain-dead systems should produce brain-dead test results. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 12:23 Dave Page <[email protected]> parent: Peter Eisentraut <[email protected]> 1 sibling, 0 replies; 333+ messages in thread From: Dave Page @ 2007-05-09 12:23 UTC (permalink / raw) To: Peter Eisentraut <[email protected]>; +Cc: pgsql-hackers; [email protected] Peter Eisentraut wrote: > Am Mittwoch, 9. Mai 2007 13:46 schrieb Dave Page: >> Can we rename the test please? > > I'm thinking no. Brain-dead systems should produce brain-dead test results. > And that helps us how exactly, on what will probably be the most widely used OS in the world within a few years? Regards, Dave. ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 12:40 Andrew Dunstan <[email protected]> parent: Peter Eisentraut <[email protected]> 1 sibling, 1 reply; 333+ messages in thread From: Andrew Dunstan @ 2007-05-09 12:40 UTC (permalink / raw) To: Peter Eisentraut <[email protected]>; +Cc: pgsql-hackers; Dave Page <[email protected]>; [email protected] Peter Eisentraut wrote: > Am Mittwoch, 9. Mai 2007 13:46 schrieb Dave Page: > >> Can we rename the test please? >> > > I'm thinking no. Brain-dead systems should produce brain-dead test results. > > Not doing this would seem like sheer bloody-mindedness. We have workarounds for craziness on many systems. Not providing for this will mean that we have to disable the ECPG tests for Vista. I don't see how that helps anyone. More seriously, we need to get the ECPG regression test rewritten in C, as was done for the main line regression tests. Maybe we need to factor out some of that into a library so the common code can be used in both programs. At any rate, until this is done we can't run the ECPG tests on MSVC builds. cheers andrew ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 12:52 Magnus Hagander <[email protected]> parent: Andrew Dunstan <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Magnus Hagander @ 2007-05-09 12:52 UTC (permalink / raw) To: Andrew Dunstan <[email protected]>; +Cc: Peter Eisentraut <[email protected]>; pgsql-hackers; Dave Page <[email protected]>; [email protected] On Wed, May 09, 2007 at 08:40:24AM -0400, Andrew Dunstan wrote: > > > Peter Eisentraut wrote: > >Am Mittwoch, 9. Mai 2007 13:46 schrieb Dave Page: > > > >>Can we rename the test please? > >> > > > >I'm thinking no. Brain-dead systems should produce brain-dead test > >results. > > > > > > Not doing this would seem like sheer bloody-mindedness. We have > workarounds for craziness on many systems. Not providing for this will > mean that we have to disable the ECPG tests for Vista. I don't see how > that helps anyone. Agreed. > More seriously, we need to get the ECPG regression test rewritten in C, > as was done for the main line regression tests. Maybe we need to factor > out some of that into a library so the common code can be used in both > programs. At any rate, until this is done we can't run the ECPG tests on > MSVC builds. IIRC, Joachim has at least started work on that. (Unrelated to vista - ecpg tests are broken on both mingw and msvc for vista) //Magnus ^ permalink raw reply [nested|flat] 333+ messages in thread
* PostgreSQL wants to install, cancel or allow? (was Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 12:55 Ned Lilly <[email protected]> parent: Dave Page <[email protected]> 3 siblings, 1 reply; 333+ messages in thread From: Ned Lilly @ 2007-05-09 12:55 UTC (permalink / raw) To: Dave Page <[email protected]>; +Cc: pgsql-hackers On 5/9/2007 7:46 AM Dave Page wrote: > Oh, hang on... Vista's new 'security' features include popups that ask > permission from the user before running any installers. One of the more > basic checks they use is the filename - *anything* called setup.exe will > cause user confirmation to be required before it will run. I believe for > non-interactive sessions it'll just refuse to run. I just tried running > update.exe myself, and yes, you guessed it, a user confirmation dialog > popped up :-( You can just disable that "feature" by turning off "User Account Control" under the Windows Security Center... ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: PostgreSQL wants to install, cancel or allow? (was Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-09 13:01 Dave Page <[email protected]> parent: Ned Lilly <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Dave Page @ 2007-05-09 13:01 UTC (permalink / raw) To: Ned Lilly <[email protected]>; +Cc: pgsql-hackers Ned Lilly wrote: > On 5/9/2007 7:46 AM Dave Page wrote: > >> Oh, hang on... Vista's new 'security' features include popups that ask >> permission from the user before running any installers. One of the >> more basic checks they use is the filename - *anything* called >> setup.exe will cause user confirmation to be required before it will >> run. I believe for non-interactive sessions it'll just refuse to run. >> I just tried running update.exe myself, and yes, you guessed it, a >> user confirmation dialog popped up :-( > > You can just disable that "feature" by turning off "User Account > Control" under the Windows Security Center... Yeah, I know, but that's not really a solution we can live with. Regards, Dave. ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-10 09:54 Michael Meskes <[email protected]> parent: Dave Page <[email protected]> 3 siblings, 1 reply; 333+ messages in thread From: Michael Meskes @ 2007-05-10 09:54 UTC (permalink / raw) To: Dave Page <[email protected]>; +Cc: [email protected]; pgsql-hackers On Wed, May 09, 2007 at 12:46:52PM +0100, Dave Page wrote: > Oh, hang on... Vista's new 'security' features include popups that ask > permission from the user before running any installers. One of the more > basic checks they use is the filename - *anything* called setup.exe will > cause user confirmation to be required before it will run. I believe for > non-interactive sessions it'll just refuse to run. I just tried running > update.exe myself, and yes, you guessed it, a user confirmation dialog > popped up :-( Seems to be a little bit braindead to me. But anyway, I renamed it and just committed the changes. Let's see if this works. Michael P.S.: More on the other problem later. -- Michael Meskes Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org) ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: [email protected] Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL! ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-10 10:05 Dave Page <[email protected]> parent: Michael Meskes <[email protected]> 0 siblings, 1 reply; 333+ messages in thread From: Dave Page @ 2007-05-10 10:05 UTC (permalink / raw) To: Dave Page <[email protected]>; [email protected]; pgsql-hackers Michael Meskes wrote: > On Wed, May 09, 2007 at 12:46:52PM +0100, Dave Page wrote: >> Oh, hang on... Vista's new 'security' features include popups that ask >> permission from the user before running any installers. One of the more >> basic checks they use is the filename - *anything* called setup.exe will >> cause user confirmation to be required before it will run. I believe for >> non-interactive sessions it'll just refuse to run. I just tried running >> update.exe myself, and yes, you guessed it, a user confirmation dialog >> popped up :-( > > Seems to be a little bit braindead to me. Yeah - according to Microsoft we should include a manifest with the executable these days that can prevent the check by specifying that administrative privileges won't be needed by the executable - but that involves us adding version resources to the exe, and generating the manifest during build which seems somewhat over the top for a quick regression test. > But anyway, I renamed it and > just committed the changes. Let's see if this works. Thanks. > P.S.: More on the other problem later. OK. Regards, Dave. ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-10 14:33 Michael Meskes <[email protected]> parent: Dave Page <[email protected]> 0 siblings, 1 reply; 333+ messages in thread From: Michael Meskes @ 2007-05-10 14:33 UTC (permalink / raw) To: Dave Page <[email protected]>; +Cc: [email protected]; pgsql-hackers On Thu, May 10, 2007 at 11:05:39AM +0100, Dave Page wrote: > > P.S.: More on the other problem later. > > OK. Dave, I just committed some small changes to get additional error logging. Hopefully this enables me to find out where exactly the error is coming up. If possible could you please restart a run on vista? Thanks Michael -- Michael Meskes Email: Michael at Fam-Meskes dot De ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: [email protected] Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL! ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-10 15:56 Dave Page <[email protected]> parent: Michael Meskes <[email protected]> 0 siblings, 1 reply; 333+ messages in thread From: Dave Page @ 2007-05-10 15:56 UTC (permalink / raw) To: [email protected]; pgsql-hackers Michael Meskes wrote: > On Thu, May 10, 2007 at 11:05:39AM +0100, Dave Page wrote: >>> P.S.: More on the other problem later. >> OK. > > Dave, I just committed some small changes to get additional error > logging. Hopefully this enables me to find out where exactly the error > is coming up. If possible could you please restart a run on vista? Running now - I won't have access to the machine again until Monday now though. Regards, Dave ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-10 19:52 Dave Page <[email protected]> parent: Dave Page <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Dave Page @ 2007-05-10 19:52 UTC (permalink / raw) To: [email protected]; pgsql-hackers Dave Page wrote: > Michael Meskes wrote: >> On Thu, May 10, 2007 at 11:05:39AM +0100, Dave Page wrote: >>>> P.S.: More on the other problem later. >>> OK. >> Dave, I just committed some small changes to get additional error >> logging. Hopefully this enables me to find out where exactly the error >> is coming up. If possible could you please restart a run on vista? > > Running now - I won't have access to the machine again until Monday now > though. It's passing what was the update test now which is good - thanks :-). Here's the results of the run, showing just the dt_test failure: http://www.pgbuildfarm.org/cgi-bin/show_log.pl?nm=vaquita&dt=2007-05-10%2015:55:16 Regards, Dave. ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-15 10:34 Michael Meskes <[email protected]> parent: Dave Page <[email protected]> 3 siblings, 1 reply; 333+ messages in thread From: Michael Meskes @ 2007-05-15 10:34 UTC (permalink / raw) To: Dave Page <[email protected]>; +Cc: [email protected]; pgsql-hackers On Wed, May 09, 2007 at 12:46:52PM +0100, Dave Page wrote: > >Unfortunately I do not have access to a Vista system I could use to test > >and track this one down. > > I'm happy to run any tests you like. Dave, could you please apply this small patch to pgtypeslib/datetime.c. I still have no clue where the error code is comming from and I'm trying to narrow it down a bit. Thanks. Michael -- Michael Meskes Email: Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org) ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: [email protected] Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL! Attachments: [text/x-diff] vista.patch (769B, ../../[email protected]/2-vista.patch) download | inline diff: --- pgtypeslib/datetime.c 2006-10-04 09:37:59.000000000 +0200 +++ datetime.c 2007-05-15 12:31:56.000000000 +0200 @@ -74,6 +74,7 @@ errno = PGTYPES_DATE_BAD_DATE; return INT_MIN; } + printf("1: errno = %d\n", errno); if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 || DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp, EuroDates) != 0) @@ -81,6 +82,7 @@ errno = PGTYPES_DATE_BAD_DATE; return INT_MIN; } + printf("2: errno = %d\n", errno); switch (dtype) { @@ -95,8 +97,10 @@ errno = PGTYPES_DATE_BAD_DATE; return INT_MIN; } + printf("3: errno = %d\n", errno); dDate = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1)); + printf("4: errno = %d\n", errno); return dDate; } ^ permalink raw reply [nested|flat] 333+ messages in thread
* Re: Windows Vista support (Buildfarm Vaquita) @ 2007-05-16 08:26 Dave Page <[email protected]> parent: Michael Meskes <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Dave Page @ 2007-05-16 08:26 UTC (permalink / raw) To: Dave Page <[email protected]>; [email protected]; pgsql-hackers Michael Meskes wrote: > On Wed, May 09, 2007 at 12:46:52PM +0100, Dave Page wrote: >>> Unfortunately I do not have access to a Vista system I could use to test >>> and track this one down. >> I'm happy to run any tests you like. > > Dave, could you please apply this small patch to pgtypeslib/datetime.c. > I still have no clue where the error code is comming from and I'm trying > to narrow it down a bit. Hi Michael, The results are attached. Please let me know if I can do anything more. Regards, Dave [NO_PID]: ECPGdebug: set to 1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 29: QUERY: create table date_test ( d date , ts timestamp ) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 29 Ok: CREATE TABLE [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 30: QUERY: set datestyle to iso on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 30 Ok: SET [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 35: QUERY: insert into date_test ( d , ts ) values ( date '1966-01-17' , timestamp '2000-07-12 17:34:29' ) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 37: QUERY: select * from date_test where d = date '1966-01-17' on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 37: Correctly got 1 tuples with 2 fields [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 errno 22 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: raising sqlcode -209 in line 37, 'SQL error #-209 in line 37.'. [NO_PID]: sqlca: code: -209, state: 42804 sql error SQL error #-209 in line 37. [NO_PID]: ECPGtrans line 350 action = rollback connection = regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_finish: Connection regress1 closed. [NO_PID]: sqlca: code: 0, state: 00000 1: errno = 0 2: errno = 22 3: errno = 22 4: errno = 22 1: errno = 0 2: errno = 22 3: errno = 22 4: errno = 22 Date: 1966-01-17 timestamp: 2000-07-12 17:34:29 interval: @ 13556 days 12 hours 34 mins 14 secs m: 4, d: 19, y: 1998 date seems to get encoded to julian -622 m: 4, d: 19, y: 1998 date_day of 2003-12-04 17:34:29 is 4 Above date in format "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end" is "(Thu), Dec. 04, 2003, repeat: (Thu), Dec. 04, 2003. end" date_defmt_asc1: 1995-12-25 date_defmt_asc2: 0095-12-25 date_defmt_asc3: 0095-12-25 date_defmt_asc4: 1995-12-25 date_defmt_asc5: 1995-12-25 date_defmt_asc6: 1995-12-25 date_defmt_asc7: 1995-12-25 date_defmt_asc8: 1995-12-25 date_defmt_asc9: 1995-12-25 date_defmt_asc10: 1995-12-25 date_defmt_asc12: 0095-12-25 timestamp_to_asc1: 1996-02-29 00:00:00 timestamp_to_asc2: 1994-02-11 03:10:35 timestamp_to_asc3: 2000-01-01 00:00:00 timestamp_fmt_asc: 0: abc-00:00:00-def-01/01/00-ghi% timestamp_defmt_asc(This is a 4/12/80 3-39l12test, This is a %m/%d/%y %H-%Ml%Stest) = 1980-04-12 03:39:12, error: 0 timestamp_defmt_asc(Tue Jul 22 17:28:44 +0200 2003, %a %b %d %H:%M:%S %z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 2000, %a %b %d %H:%M:%S %z %Y) = 2000-02-29 15:28:44, error: 0 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 1900, %a %b %d %H:%M:%S %z %Y) = 1900-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 1996, %a %b %d %H:%M:%S %z %Y) = 1996-02-29 15:28:44, error: 0 timestamp_defmt_asc( Jul 31 17:28:44 +0200 1996, %b %d %H:%M:%S %z %Y) = 1996-07-31 15:28:44, error: 0 timestamp_defmt_asc( Jul 32 17:28:44 +0200 1996, %b %d %H:%M:%S %z %Y) = 1996-07-31 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 1997, %a %b %d %H:%M:%S %z %Y) = 1997-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Jul 22 17:28:44 +0200 2003, %) = 1997-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Jul 22 17:28:44 +0200 2003, a %) = 1997-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc( Jul, 22 17_28 `44 +0200 2003 , %b, %d %H_%M`%S %z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(Tue Jul %22 17:28:44 CEST 2003, %a %b %%%d %H:%M:%S %Z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(Tue Jul %22 17:28:44 CEST 2003, %a %b %%%d %H:%M:%S %Z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(abc 19 October %22 17:28:44 CEST 2003, abc%n %C %B %%%d %H:%M:%S %Z %Y) = 2003-10-22 15:28:44, error: 0 timestamp_defmt_asc(abc 18 October %34 17:28:44 CEST 80, abc%n %C %B %%%d %H:%M:%S %Z %y) = 1880-10-31 15:28:44, error (should be error!): 1 timestamp_defmt_asc(abc 18 October %34 17:28:44 CEST 80, ) = 1880-10-31 15:28:44, error (should be error!): 1 timestamp_defmt_asc(1980-04-12 3:49:44 , NULL) = 1980-04-12 03:49:44, error: 0 timestamp_defmt_asc(July 14, 1988. Time: 9:15am, %B %d, %Y. Time: %I:%M%p) = 1988-07-14 09:15:00, error: 0 timestamp_defmt_asc(September 6 at 01:30 pm in the year 1983, %B %d at %I:%M %p in the year %Y) = 1983-09-06 13:30:00, error: 0 timestamp_defmt_asc( 1976, July 14. Time: 9:15am, %Y, %B %d. Time: %I:%M %p) = 1976-07-14 09:15:00, error: 0 timestamp_defmt_asc( 1976, July 14. Time: 9:15 am, %Y, %B %d. Time: %I:%M%p) = 1976-07-14 09:15:00, error: 0 timestamp_defmt_asc( 1976, P.M. July 14. Time: 9:15, %Y, %P %B %d. Time: %I:%M) = 1976-07-14 21:15:00, error: 0 *** expected/pgtypeslib-dt_test.stderr Sat Mar 17 19:25:23 2007 --- results/pgtypeslib-dt_test.stderr Wed May 16 09:14:04 2007 *************** *** 20,27 **** [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 ! [NO_PID]: ECPGget_data line 37: RESULT: 2000-07-12 17:34:29 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGtrans line 350 action = rollback connection = regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_finish: Connection regress1 closed. --- 20,30 ---- [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 ! [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 errno 22 [NO_PID]: sqlca: code: 0, state: 00000 + [NO_PID]: raising sqlcode -209 in line 37, 'SQL error #-209 in line 37.'. + [NO_PID]: sqlca: code: -209, state: 42804 + sql error SQL error #-209 in line 37. [NO_PID]: ECPGtrans line 350 action = rollback connection = regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_finish: Connection regress1 closed. *** expected/pgtypeslib-dt_test.stdout Mon Aug 7 14:17:02 2006 --- results/pgtypeslib-dt_test.stdout Wed May 16 09:14:04 2007 *************** *** 1,3 **** --- 1,11 ---- + 1: errno = 0 + 2: errno = 22 + 3: errno = 22 + 4: errno = 22 + 1: errno = 0 + 2: errno = 22 + 3: errno = 22 + 4: errno = 22 Date: 1966-01-17 timestamp: 2000-07-12 17:34:29 interval: @ 13556 days 12 hours 34 mins 14 secs *** expected/pgtypeslib-dt_test2.stdout Thu Sep 14 09:02:38 2006 --- results/pgtypeslib-dt_test2.stdout Wed May 16 09:14:06 2007 *************** *** 1,88 **** --- 1,159 ---- timestamp: 2003-12-04 17:34:29 Date of timestamp: 2003-12-04 + 1: errno = 0 Date[0]: - (N - T) + 1: errno = 0 Date[1]: - (N - T) + 1: errno = 0 Date[2]: - (N - T) + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[3]: 1999-01-08 (N - F) TS[3,0]: 1999-01-08 00:04:00 TS[3,1]: 1999-01-08 01:59:00 TS[3,2]: 1999-01-08 13:24:40 TS[3,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[4]: 1999-01-08 (N - F) TS[4,0]: 1999-01-08 00:04:00 TS[4,1]: 1999-01-08 01:59:00 TS[4,2]: 1999-01-08 13:24:40 TS[4,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[5]: 1999-01-08 (N - F) TS[5,0]: 1999-01-08 00:04:00 TS[5,1]: 1999-01-08 01:59:00 TS[5,2]: 1999-01-08 13:24:40 TS[5,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[6]: 1999-01-18 (N - F) TS[6,0]: 1999-01-18 00:04:00 TS[6,1]: 1999-01-18 01:59:00 TS[6,2]: 1999-01-18 13:24:40 TS[6,3]: 1999-01-18 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[7]: 2003-01-02 (N - F) TS[7,0]: 2003-01-02 00:04:00 TS[7,1]: 2003-01-02 01:59:00 TS[7,2]: 2003-01-02 13:24:40 TS[7,3]: 2003-01-02 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[8]: 1999-01-08 (N - F) TS[8,0]: 1999-01-08 00:04:00 TS[8,1]: 1999-01-08 01:59:00 TS[8,2]: 1999-01-08 13:24:40 TS[8,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[9]: 1999-01-08 (N - F) TS[9,0]: 1999-01-08 00:04:00 TS[9,1]: 1999-01-08 01:59:00 TS[9,2]: 1999-01-08 13:24:40 TS[9,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[10]: 1999-01-08 (N - F) TS[10,0]: 1999-01-08 00:04:00 TS[10,1]: 1999-01-08 01:59:00 TS[10,2]: 1999-01-08 13:24:40 TS[10,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[11]: 1999-01-08 (N - F) TS[11,0]: 1999-01-08 00:04:00 TS[11,1]: 1999-01-08 01:59:00 TS[11,2]: 1999-01-08 13:24:40 TS[11,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[12]: 1999-01-08 (N - F) TS[12,0]: 1999-01-08 00:04:00 TS[12,1]: 1999-01-08 01:59:00 TS[12,2]: 1999-01-08 13:24:40 TS[12,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[13]: 2006-01-08 (N - F) TS[13,0]: 2006-01-08 00:04:00 TS[13,1]: 2006-01-08 01:59:00 TS[13,2]: 2006-01-08 13:24:40 TS[13,3]: 2006-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[14]: 1999-01-08 (N - F) TS[14,0]: 1999-01-08 00:04:00 TS[14,1]: 1999-01-08 01:59:00 TS[14,2]: 1999-01-08 13:24:40 TS[14,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[15]: 1999-01-08 (N - F) TS[15,0]: 1999-01-08 00:04:00 TS[15,1]: 1999-01-08 01:59:00 TS[15,2]: 1999-01-08 13:24:40 TS[15,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[16]: 1999-01-08 (N - F) TS[16,0]: 1999-01-08 00:04:00 TS[16,1]: 1999-01-08 01:59:00 TS[16,2]: 1999-01-08 13:24:40 TS[16,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[17]: 1999-01-08 (N - F) TS[17,0]: 1999-01-08 00:04:00 TS[17,1]: 1999-01-08 01:59:00 TS[17,2]: 1999-01-08 13:24:40 TS[17,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[18]: 1999-01-08 (N - F) TS[18,0]: 1999-01-08 00:04:00 TS[18,1]: 1999-01-08 01:59:00 TS[18,2]: 1999-01-08 13:24:40 TS[18,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[19]: 0099-01-08 BC (N - F) TS[19,0]: 0099-01-08 00:04:00 BC TS[19,1]: 0099-01-08 01:59:00 BC Attachments: [text/plain] pgtypeslib-dt_test.stderr (1.7K, ../../[email protected]/2-pgtypeslib-dt_test.stderr) download | inline: [NO_PID]: ECPGdebug: set to 1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 29: QUERY: create table date_test ( d date , ts timestamp ) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 29 Ok: CREATE TABLE [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 30: QUERY: set datestyle to iso on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 30 Ok: SET [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 35: QUERY: insert into date_test ( d , ts ) values ( date '1966-01-17' , timestamp '2000-07-12 17:34:29' ) on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 37: QUERY: select * from date_test where d = date '1966-01-17' on connection regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGexecute line 37: Correctly got 1 tuples with 2 fields [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 errno 22 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: raising sqlcode -209 in line 37, 'SQL error #-209 in line 37.'. [NO_PID]: sqlca: code: -209, state: 42804 sql error SQL error #-209 in line 37. [NO_PID]: ECPGtrans line 350 action = rollback connection = regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_finish: Connection regress1 closed. [NO_PID]: sqlca: code: 0, state: 00000 [text/plain] pgtypeslib-dt_test.stdout (3.4K, ../../[email protected]/3-pgtypeslib-dt_test.stdout) download | inline: 1: errno = 0 2: errno = 22 3: errno = 22 4: errno = 22 1: errno = 0 2: errno = 22 3: errno = 22 4: errno = 22 Date: 1966-01-17 timestamp: 2000-07-12 17:34:29 interval: @ 13556 days 12 hours 34 mins 14 secs m: 4, d: 19, y: 1998 date seems to get encoded to julian -622 m: 4, d: 19, y: 1998 date_day of 2003-12-04 17:34:29 is 4 Above date in format "(ddd), mmm. dd, yyyy, repeat: (ddd), mmm. dd, yyyy. end" is "(Thu), Dec. 04, 2003, repeat: (Thu), Dec. 04, 2003. end" date_defmt_asc1: 1995-12-25 date_defmt_asc2: 0095-12-25 date_defmt_asc3: 0095-12-25 date_defmt_asc4: 1995-12-25 date_defmt_asc5: 1995-12-25 date_defmt_asc6: 1995-12-25 date_defmt_asc7: 1995-12-25 date_defmt_asc8: 1995-12-25 date_defmt_asc9: 1995-12-25 date_defmt_asc10: 1995-12-25 date_defmt_asc12: 0095-12-25 timestamp_to_asc1: 1996-02-29 00:00:00 timestamp_to_asc2: 1994-02-11 03:10:35 timestamp_to_asc3: 2000-01-01 00:00:00 timestamp_fmt_asc: 0: abc-00:00:00-def-01/01/00-ghi% timestamp_defmt_asc(This is a 4/12/80 3-39l12test, This is a %m/%d/%y %H-%Ml%Stest) = 1980-04-12 03:39:12, error: 0 timestamp_defmt_asc(Tue Jul 22 17:28:44 +0200 2003, %a %b %d %H:%M:%S %z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 2000, %a %b %d %H:%M:%S %z %Y) = 2000-02-29 15:28:44, error: 0 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 1900, %a %b %d %H:%M:%S %z %Y) = 1900-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 1996, %a %b %d %H:%M:%S %z %Y) = 1996-02-29 15:28:44, error: 0 timestamp_defmt_asc( Jul 31 17:28:44 +0200 1996, %b %d %H:%M:%S %z %Y) = 1996-07-31 15:28:44, error: 0 timestamp_defmt_asc( Jul 32 17:28:44 +0200 1996, %b %d %H:%M:%S %z %Y) = 1996-07-31 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Feb 29 17:28:44 +0200 1997, %a %b %d %H:%M:%S %z %Y) = 1997-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Jul 22 17:28:44 +0200 2003, %) = 1997-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc(Tue Jul 22 17:28:44 +0200 2003, a %) = 1997-02-28 15:28:44, error (should be error!): 1 timestamp_defmt_asc( Jul, 22 17_28 `44 +0200 2003 , %b, %d %H_%M`%S %z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(Tue Jul %22 17:28:44 CEST 2003, %a %b %%%d %H:%M:%S %Z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(Tue Jul %22 17:28:44 CEST 2003, %a %b %%%d %H:%M:%S %Z %Y) = 2003-07-22 15:28:44, error: 0 timestamp_defmt_asc(abc 19 October %22 17:28:44 CEST 2003, abc%n %C %B %%%d %H:%M:%S %Z %Y) = 2003-10-22 15:28:44, error: 0 timestamp_defmt_asc(abc 18 October %34 17:28:44 CEST 80, abc%n %C %B %%%d %H:%M:%S %Z %y) = 1880-10-31 15:28:44, error (should be error!): 1 timestamp_defmt_asc(abc 18 October %34 17:28:44 CEST 80, ) = 1880-10-31 15:28:44, error (should be error!): 1 timestamp_defmt_asc(1980-04-12 3:49:44 , NULL) = 1980-04-12 03:49:44, error: 0 timestamp_defmt_asc(July 14, 1988. Time: 9:15am, %B %d, %Y. Time: %I:%M%p) = 1988-07-14 09:15:00, error: 0 timestamp_defmt_asc(September 6 at 01:30 pm in the year 1983, %B %d at %I:%M %p in the year %Y) = 1983-09-06 13:30:00, error: 0 timestamp_defmt_asc( 1976, July 14. Time: 9:15am, %Y, %B %d. Time: %I:%M %p) = 1976-07-14 09:15:00, error: 0 timestamp_defmt_asc( 1976, July 14. Time: 9:15 am, %Y, %B %d. Time: %I:%M%p) = 1976-07-14 09:15:00, error: 0 timestamp_defmt_asc( 1976, P.M. July 14. Time: 9:15, %Y, %P %B %d. Time: %I:%M) = 1976-07-14 21:15:00, error: 0 [text/plain] regression.diffs (5.7K, ../../[email protected]/4-regression.diffs) download | inline: *** expected/pgtypeslib-dt_test.stderr Sat Mar 17 19:25:23 2007 --- results/pgtypeslib-dt_test.stderr Wed May 16 09:14:04 2007 *************** *** 20,27 **** [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 ! [NO_PID]: ECPGget_data line 37: RESULT: 2000-07-12 17:34:29 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGtrans line 350 action = rollback connection = regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_finish: Connection regress1 closed. --- 20,30 ---- [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 offset: -1 array: Yes [NO_PID]: sqlca: code: 0, state: 00000 ! [NO_PID]: ECPGget_data line 37: RESULT: 1966-01-17 errno 22 [NO_PID]: sqlca: code: 0, state: 00000 + [NO_PID]: raising sqlcode -209 in line 37, 'SQL error #-209 in line 37.'. + [NO_PID]: sqlca: code: -209, state: 42804 + sql error SQL error #-209 in line 37. [NO_PID]: ECPGtrans line 350 action = rollback connection = regress1 [NO_PID]: sqlca: code: 0, state: 00000 [NO_PID]: ecpg_finish: Connection regress1 closed. *** expected/pgtypeslib-dt_test.stdout Mon Aug 7 14:17:02 2006 --- results/pgtypeslib-dt_test.stdout Wed May 16 09:14:04 2007 *************** *** 1,3 **** --- 1,11 ---- + 1: errno = 0 + 2: errno = 22 + 3: errno = 22 + 4: errno = 22 + 1: errno = 0 + 2: errno = 22 + 3: errno = 22 + 4: errno = 22 Date: 1966-01-17 timestamp: 2000-07-12 17:34:29 interval: @ 13556 days 12 hours 34 mins 14 secs *** expected/pgtypeslib-dt_test2.stdout Thu Sep 14 09:02:38 2006 --- results/pgtypeslib-dt_test2.stdout Wed May 16 09:14:06 2007 *************** *** 1,88 **** --- 1,159 ---- timestamp: 2003-12-04 17:34:29 Date of timestamp: 2003-12-04 + 1: errno = 0 Date[0]: - (N - T) + 1: errno = 0 Date[1]: - (N - T) + 1: errno = 0 Date[2]: - (N - T) + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[3]: 1999-01-08 (N - F) TS[3,0]: 1999-01-08 00:04:00 TS[3,1]: 1999-01-08 01:59:00 TS[3,2]: 1999-01-08 13:24:40 TS[3,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[4]: 1999-01-08 (N - F) TS[4,0]: 1999-01-08 00:04:00 TS[4,1]: 1999-01-08 01:59:00 TS[4,2]: 1999-01-08 13:24:40 TS[4,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[5]: 1999-01-08 (N - F) TS[5,0]: 1999-01-08 00:04:00 TS[5,1]: 1999-01-08 01:59:00 TS[5,2]: 1999-01-08 13:24:40 TS[5,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[6]: 1999-01-18 (N - F) TS[6,0]: 1999-01-18 00:04:00 TS[6,1]: 1999-01-18 01:59:00 TS[6,2]: 1999-01-18 13:24:40 TS[6,3]: 1999-01-18 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[7]: 2003-01-02 (N - F) TS[7,0]: 2003-01-02 00:04:00 TS[7,1]: 2003-01-02 01:59:00 TS[7,2]: 2003-01-02 13:24:40 TS[7,3]: 2003-01-02 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[8]: 1999-01-08 (N - F) TS[8,0]: 1999-01-08 00:04:00 TS[8,1]: 1999-01-08 01:59:00 TS[8,2]: 1999-01-08 13:24:40 TS[8,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[9]: 1999-01-08 (N - F) TS[9,0]: 1999-01-08 00:04:00 TS[9,1]: 1999-01-08 01:59:00 TS[9,2]: 1999-01-08 13:24:40 TS[9,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[10]: 1999-01-08 (N - F) TS[10,0]: 1999-01-08 00:04:00 TS[10,1]: 1999-01-08 01:59:00 TS[10,2]: 1999-01-08 13:24:40 TS[10,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[11]: 1999-01-08 (N - F) TS[11,0]: 1999-01-08 00:04:00 TS[11,1]: 1999-01-08 01:59:00 TS[11,2]: 1999-01-08 13:24:40 TS[11,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[12]: 1999-01-08 (N - F) TS[12,0]: 1999-01-08 00:04:00 TS[12,1]: 1999-01-08 01:59:00 TS[12,2]: 1999-01-08 13:24:40 TS[12,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[13]: 2006-01-08 (N - F) TS[13,0]: 2006-01-08 00:04:00 TS[13,1]: 2006-01-08 01:59:00 TS[13,2]: 2006-01-08 13:24:40 TS[13,3]: 2006-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[14]: 1999-01-08 (N - F) TS[14,0]: 1999-01-08 00:04:00 TS[14,1]: 1999-01-08 01:59:00 TS[14,2]: 1999-01-08 13:24:40 TS[14,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[15]: 1999-01-08 (N - F) TS[15,0]: 1999-01-08 00:04:00 TS[15,1]: 1999-01-08 01:59:00 TS[15,2]: 1999-01-08 13:24:40 TS[15,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[16]: 1999-01-08 (N - F) TS[16,0]: 1999-01-08 00:04:00 TS[16,1]: 1999-01-08 01:59:00 TS[16,2]: 1999-01-08 13:24:40 TS[16,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[17]: 1999-01-08 (N - F) TS[17,0]: 1999-01-08 00:04:00 TS[17,1]: 1999-01-08 01:59:00 TS[17,2]: 1999-01-08 13:24:40 TS[17,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[18]: 1999-01-08 (N - F) TS[18,0]: 1999-01-08 00:04:00 TS[18,1]: 1999-01-08 01:59:00 TS[18,2]: 1999-01-08 13:24:40 TS[18,3]: 1999-01-08 13:24:40.495 + 1: errno = 0 + 2: errno = 0 + 3: errno = 0 + 4: errno = 0 Date[19]: 0099-01-08 BC (N - F) TS[19,0]: 0099-01-08 00:04:00 BC TS[19,1]: 0099-01-08 01:59:00 BC ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
* [PATCH v7 2/3] Handle default tablespace in AlterTableInternal @ 2025-08-04 22:05 Erik Wienhold <[email protected]> 0 siblings, 0 replies; 333+ messages in thread From: Erik Wienhold @ 2025-08-04 22:05 UTC (permalink / raw) Move handling of default tablespace for CREATE OR REPLACE MATERIALIZED VIEW from create_ctas_internal to ATPrepSetTableSpace. It feels cleaner that way in my opinion by not having to resolve the tablespace name just to pass it to AlterTableInternal. The default table space is passed as empty string to AlterTableInternal. --- src/backend/commands/createas.c | 21 ++------------------- src/backend/commands/tablecmds.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 1620273f965..30ca0a21903 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -24,7 +24,6 @@ */ #include "postgres.h" -#include "miscadmin.h" #include "access/heapam.h" #include "access/reloptions.h" #include "access/tableam.h" @@ -35,7 +34,6 @@ #include "commands/matview.h" #include "commands/prepare.h" #include "commands/tablecmds.h" -#include "commands/tablespace.h" #include "commands/view.h" #include "executor/execdesc.h" #include "executor/executor.h" @@ -160,23 +158,8 @@ create_ctas_internal(List *attrList, IntoClause *into) /* tablespace */ atcmd = makeNode(AlterTableCmd); atcmd->subtype = AT_SetTableSpace; - if (into->tableSpaceName != NULL) - atcmd->name = into->tableSpaceName; - else - { - Oid spcid; - - /* - * Resolve the name of the default or database tablespace because - * we need to specify the tablespace by name. - * - * TODO: Move that to ATPrepSetTableSpace? Must allow AlterTableCmd.name to be NULL then. - */ - spcid = GetDefaultTablespace(RELPERSISTENCE_PERMANENT, false); - if (!OidIsValid(spcid)) - spcid = MyDatabaseTableSpace; - atcmd->name = get_tablespace_name(spcid); - } + /* use empty string to specify default tablespace */ + atcmd->name = into->tableSpaceName ? into->tableSpaceName : ""; atcmds = lappend(atcmds, atcmd); /* storage options */ diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 44dcd2c5b0d..6ec0b87f841 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -16580,8 +16580,18 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, const char *tablespacen { Oid tablespaceId; - /* Check that the tablespace exists */ - tablespaceId = get_tablespace_oid(tablespacename, false); + if (tablespacename != NULL && tablespacename[0] == '\0') + { + /* Use default tablespace if name is empty string */ + tablespaceId = GetDefaultTablespace(rel->rd_rel->relpersistence, rel->rd_rel->relispartition); + if (!OidIsValid(tablespaceId)) + tablespaceId = MyDatabaseTableSpace; + } + else + { + /* Check that the tablespace exists */ + tablespaceId = get_tablespace_oid(tablespacename, false); + } /* Check permissions except when moving to database's default */ if (OidIsValid(tablespaceId) && tablespaceId != MyDatabaseTableSpace) -- 2.50.1 --r33ycpluvyfavkwy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v7-0003-Add-WITH-OLD-DATA-to-CREATE-OR-REPLACE-MATERIALIZ.patch" ^ permalink raw reply [nested|flat] 333+ messages in thread
end of thread, other threads:[~2025-08-04 22:05 UTC | newest] Thread overview: 333+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2007-05-09 08:21 Windows Vista support (Buildfarm Vaquita) Dave Page <[email protected]> 2007-05-09 09:01 ` Michael Meskes <[email protected]> 2007-05-09 11:46 ` Dave Page <[email protected]> 2007-05-09 12:20 ` Peter Eisentraut <[email protected]> 2007-05-09 12:23 ` Dave Page <[email protected]> 2007-05-09 12:40 ` Andrew Dunstan <[email protected]> 2007-05-09 12:52 ` Magnus Hagander <[email protected]> 2007-05-09 12:55 ` PostgreSQL wants to install, cancel or allow? (was Re: Windows Vista support (Buildfarm Vaquita) Ned Lilly <[email protected]> 2007-05-09 13:01 ` Re: PostgreSQL wants to install, cancel or allow? (was Re: Windows Vista support (Buildfarm Vaquita) Dave Page <[email protected]> 2007-05-10 09:54 ` Michael Meskes <[email protected]> 2007-05-10 10:05 ` Dave Page <[email protected]> 2007-05-10 14:33 ` Michael Meskes <[email protected]> 2007-05-10 15:56 ` Dave Page <[email protected]> 2007-05-10 19:52 ` Dave Page <[email protected]> 2007-05-15 10:34 ` Michael Meskes <[email protected]> 2007-05-16 08:26 ` Dave Page <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace in AlterTableInternal Erik Wienhold <[email protected]> 2025-08-04 22:05 [PATCH v7 2/3] Handle default tablespace 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