I want to create a unlogged table based on the result of another query something like
Create table table_1
as
select * from table_2
where <<conditions>>
partition by LIST(col);
Obviously this throws an error and I am unable to find whether it is even possible in postgres or not.
I appreciate any help on this.
Edit: I know I can do it by creating the table 1st and then inserting data based on the above select statement. I am however looking for a neat way to do in 1 step.
Not possible because you have to create the child tables, the partitions, as well. But what you could do, is using LIKE to copy the structure that you need, create the partitions and then use INSERT .. SELECT .. to get the data that you need.
For performance it's better to wrap it into a single transaction.
Something like this: