RE: How to select 200 columns in one SQL query
You can implement ‘for loop’ in postgres sql. However it’s not as easy as just write a for loop in a select statement because loops are not part of the SQL language.
You can use this as an example:
First, create a table to hold the results:
create table data.test (result int);
Use DO and a for loop to inserting the results :
declare rec RECORD;
for rec in SELECT column_name
WHERE table_schema = 'data’
AND table_name = ‘items’
insert into data.test select count(rec) from data.items;
Loops is part of control structures (https://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-CONTROL-STRUCTURES-LOOPS) and it’s pretty advanced. In my experience, I used more of bash script or python connection to run this.
RE: Permission denied when running the copy command.
Hi, please refer to this question on stack overflow:
If you need additional help, please let me know