Re: How to insert from linux to postgreSQL

From: Scott Whitney <scott(at)journyx(dot)com>
To: "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org>, Ron <ronljohnsonjr(at)gmail(dot)com>
Subject: Re: How to insert from linux to postgreSQL
Date: 2019-04-08 19:20:03
Message-ID: MWHPR11MB1279CD7498B9F15E049FEF19A72C0@MWHPR11MB1279.namprd11.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Is the log file "ready" for INSERT, line by line? If not, you need to preprocess it. The 2 solutions I would use are psycopg for Python or sed + INSERT depending.
________________________________
From: Ron <ronljohnsonjr(at)gmail(dot)com>
Sent: Monday, April 8, 2019 2:18:18 PM
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: How to insert from linux to postgreSQL

On 4/8/19 2:03 PM, Campbell, Lance wrote:
PostgreSQL 10.x

Use case:
I want to read a log file on my linux server and write each line out to a row in a postgreSQL table.

Presumably some manipulations need to be performed so that you can't just do COPY FROM STDIN?

When I do inserts however I want to make sure I am using prepared statements to avoid SQL injections. I know how to do this is Java but I have not found an example using a linux bash scripts.

Does anyone have an example they could point me to?

I think the problem is that you need an open connection to use prepared statements, and you can't do that in bash. What about using Python? (After all, that's a scripting language, too.)

--
Angular momentum makes the world go 'round.

[http://journyx.com/emailImages/ScottWhitney.png]

[http://journyx.com/emailImages/linkedin.png]<https://www.linkedin.com/company/journyx-inc/> [http://journyx.com/emailImages/twitter.png] <https://www.twitter.com/journyxinc>
[http://journyx.com/emailImages/bluebar.jpg]

Scott Whitney
Director of IT

[http://journyx.com/emailImages/journyx.jpg]

scott(at)journyx(dot)com<mailto:scott(at)journyx(dot)com> | +1 (800) 755-9878

7600 Burnet Road, Ste. 300
Austin, TX 78757

Visit us at www.journyx.com<https://www.journyx.com/>

To unsubscribe from Journyx promotional emails, click here <http://journyx.com/communication-preferences> or visit http://journyx.com/communication-preferences.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Rui DeSousa 2019-04-08 19:33:42 Re: How to insert from linux to postgreSQL
Previous Message Ron 2019-04-08 19:18:18 Re: How to insert from linux to postgreSQL