Answer the question
In order to leave comments, you need to log in
How to automate the execution of a sql script (vertica)?
There is a task to unload data from the database, now the city and the number of required records are manually specified in the script - it is cut off by limit'om.
I accordingly have an excel table A with a list of cities and limits for each of them.
How can this business be automated? Those. roughly speaking, so that the script is executed as many times as there are cities in table A and so that the next city and its limits are substituted into the script itself at each execution.
The first thought is to throw the list of cities into csv, create a temporary table from it, add an inner join to the script for the cities from this table, so we get data for all the necessary cities, but what about the limits, how then to leave only the required number of records ... (doing it manually later in excel is not an option)
It seems that dynamic sql is suitable for the task, but it is not supported in vertica.
Answer the question
In order to leave comments, you need to log in
Uploading csv is a good idea.
The limit effect can be achieved by analytic functions, eg
select *
from
(
select ROW_NUMBER() OVER (PARTITION BY t.city) as limit_num,
t.city
t. ...
from
(
select city, ...
from my_table m join cities c on c.city = m.city
) as t
) tt
where tt.limit_num <= 1000;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question