

Where spectrum.sales_event.eventid = event.eventid Select spectrum.sales_event.salesmonth, event.eventname, sum(spectrum.sales_event.pricepaid) Run the following query to select data from the partitioned table. Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-03/event=103/' Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-03/event=102/' Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-03/event=101/' Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-02/event=103/' Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-02/event=102/' Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-02/event=101/'

Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-01/event=103/' Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-01/event=102/' Location 's3://redshift-downloads/tickit/spectrum/salesevent/salesmonth=2008-01/event=101/' The following example adds partitions for The location of the partition folder in Amazon S3. PARTITION, add each partition, specifying the partition column and key value, and The data type canīe SMALLINT, INTEGER, BIGINT, DECIMAL, REAL, DOUBLE PRECISION, BOOLEAN, CHAR, VARCHAR, DATE, or TIMESTAMP data type. The partition key can't be the name of a table column. , _, or #) or end with a tilde (~).Ĭreate an external table and specify the partition key in the PARTITIONED BY Redshift Spectrum ignores hidden files and files that begin with a Redshift Spectrum scans the files in the partition folder and any For example, if you partition by date, you might haveĪnd so on. Store your data in folders in Amazon S3 according to your partition key.Ĭreate one folder for each partition value and name the folder with the Include the $path, $size, and $spectrum_oidĬolumn names in your query, as the following example shows. A SELECT * clause doesn't return the pseudocolumns. $size, and $spectrum_oid column names with double quotation For an example, see Example: Performing correlated subqueries in Redshift Spectrum. Perform correlated queries with Redshift Spectrum. The $spectrum_oid column provides the ability to Select the $pathĬolumn to view the path to the data files onĪnd select the $size column to view the size of the data files for each row Pseudocolumnsīy default, Amazon Redshift creates external tables with the pseudocolumns $path, To view external tables, query the SVV_EXTERNAL_TABLES system view. V_column_name varchar(6) := quote_ident(to_char(date_trunc(''month'', current_date - interval ''14 month''), ''yyyymm'')) -quote_ident() will add double quotes.Location 's3://redshift-downloads/tickit/spectrum/sales/' create or replace procedure public.rebuild_test_table() Back to the original request, please also of note that using an entirely numeric column name will require the use of double quotes every time you reference the column and mistakes by users regarding this will assuredly occur and cause their own confusion.Ĭaveats and recommendations aside, here is a very quick implementation that should be close to what you specifically asked about. For example, your dynamically named column could be replaced with a column named "as_of_month" where you simply include which month you care about in the WHERE clause of your query - for example: select * from test where as_of_month = '202303' Not knowing your exact use case, perhaps that would be: create table temp as select to_char(year_month,'YYYYMM') as as_of_month, count(psid) from tb_app_opened_globoplay_redu group by to_char(year_month,'YYYYMM') where you can then query for your character formatted year month of 13 months ago.

This is less true if you are adding a new column for each month, but I would still then recommend a different architecture.
#Redshift create table as select code
This is especially true if you plan to replace the previous name with a new name because the downstream code will fail if the column name doesn't exist (yet). For example downstream code generally needs to know what columns exist and what their names are.
#Redshift create table as select how to
I have provided an example of how to do that below, but I would caution that this is a problematic solution. To make a dynamically named column name you will need to use dynamic SQL - a SQL statement defined as a character string in code and then executed.
