insert a text file into a variable in order to insert into a bytea column

Поиск
Список
Период
Сортировка
От Arthur Lewis
Тема insert a text file into a variable in order to insert into a bytea column
Дата
Msg-id 1668948418.7183478.1454004653187.JavaMail.root@hypermediasystems.com
обсуждение исходный текст
Ответы Re: insert a text file into a variable in order to insert into a bytea column
Список pgsql-sql
Hello,
I have a file called file.txt that is 53604 bytes.  When I do the following

\set stext `cat file.txt`

select length(:'stext'); length
-------- 53603

it seems that one byte (the last newline character) is chomped off.  How can I import a text file into a variable and
insertit into a bytea column without losing the last newline byte.
 

What I want to do is something like this:

\set stext `cat file.txt`
insert into stored_files (file_name,file_text) values ('file',:'stext');

without losing a character within the variable stext.

In table stored_files, file_name is text and file_text is bytea.

I'm using psql 9.3.10 on Ubuntu 14 Linux (32 bit.)
I cannot use pg_read_file because that is for the server side, and I'm on the client side.

There should be an easy way to get a text file into a database column.

Thank you,
Arthur Lewis



В списке pgsql-sql по дате отправления:

Предыдущее
От: "Venkatesan, Sekhar"
Дата:
Сообщение: Re: PostgreSQL: Autocommit through windows odbc driver doesnt work!!!
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: insert a text file into a variable in order to insert into a bytea column