Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL import file

In PostgreSQL and bash(linux), are there ways to directly import a file from the filesystem like

[execute.sh]

pgsql .... -f insert.txt

[insert.txt]

insert into table(id,file) values(1,import('/path/to/file'))

There seems to be no import function, bytea_import as well, lo_import would save int and I don't know how to get the file back (these files are in small sizes so using lo_import seems not appropriate)

And can how do I move the insert.txt statement to PostgreSQL?

like image 832
monmonja Avatar asked Apr 10 '26 01:04

monmonja


1 Answers

I'm not sure what you're after, but if you have script with SQL-statements, for example the insert statements that you mention, you can run psql and then run the script from within psql. For example:

postgres@server:~$ psql dbname
psql (8.4.1)
Type "help" for help.

dbname=# \i /tmp/queries.sql

This will run the statements in /tmp/queries.sql.

Hope this was what you asked for.

like image 81
John P Avatar answered Apr 12 '26 13:04

John P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!