1

im importing data in postgresql with the following command:

COPY test FROM PROGRAM 'curl https://example.com/events/123&start_date=20210331T191500Z' ;

i have to manually change the "&startdate=***" to only get the data from the last hour everytime i import something. I would like to know if there is a variable i could insert in the "startdate" part of the url so it always corresponds to an hour past the current time. Thanks in advance.

1 Answer 1

5

Parameters can only be used with SELECT, INSERT, UPDATE and DELETE in PostgreSQL.

If you need a parameterized COPY statement, you have to construct an SQL string using the parameter and send that. How exactly you construct a query string depends on the programming language you are using.

In PL/pgSQL, the standard stored procedure language of PostgreSQL, it would for example look like

EXECUTE format(
           'COPY test FROM PROGRAM ''curl https://example.com/events/123&start_date=%s''',
           '20210331T191500Z'
        );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.