Re: Howto import regularly some CSV files with variing names?

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Andreas <maps(dot)on(at)gmx(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Howto import regularly some CSV files with variing names?
Date: 2013-09-24 01:14:24
Message-ID: 5240E770.2010901@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/23/2013 05:47 PM, Andreas wrote:
> Am 24.09.2013 02:25, schrieb Adrian Klaver:
>> On 09/23/2013 05:19 PM, Andreas wrote:
>>>
>>> I need to import some log-files of an application [...]
>>> The import would be easy if the files had a constant name but the app
>>> creates csv files with names like "ExportYYYYMMDD".
>>>
>>>
>>> So how would I get the filenames into the sql-script?
>>
>> Do man on find and look for -exec.
>>
>
> I could find the files and exec a shell script but how can I have a SQL
> script take the found filenames as parameter?
>
> The SQL script needs to create a temp table
> then COPY the file with the filename it got as parameter into the temp
> table
> then insert from there into the log-table
>
> How would I get the filenames into the SQL script?

Just a thought:

1) Create a function that encapsulates the above logic where the
argument is the file name.

2) Create a shell script. Use substitution to take the filename passed
to the shell script to build a string and in the script do

psql -d db_name -U user_name -c 'select the function(filename)'

2a) Use alternate language to do 2).
--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ray Stell 2013-09-24 02:30:47 Re: streaming replication not working
Previous Message hxreno1 2013-09-24 01:10:16 Re: How to create recurrence schedule event?