bytea

ERROR: column “publish_date” is of type date but expression is of type bytea

孤街醉人 提交于 2019-12-25 12:32:29
问题 I'm trying to insert objects of type Book into a database, and one of the columns is specified as date, but according to this exception: Caused by: org.postgresql.util.PSQLException: ERROR: column "publish_date" is of type date but expression is of type bytea Hint: You will need to rewrite or cast the expression. Position: 94 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412) at org.postgresql.core.v3.QueryExecutorImpl.processResults

Alphanumeric Sorting in PostgreSQL

空扰寡人 提交于 2019-12-23 16:54:58
问题 I have this table with a character varying column in Postgres 9.6: id | column ------------ 1 |IR ABC-1 2 |IR ABC-2 3 |IR ABC-10 I see some solutions typecasting the column as bytea . select * from table order by column::bytea. But it always results to: id | column ------------ 1 |IR ABC-1 2 |IR ABC-10 3 |IR ABC-2 I don't know why '10' always comes before '2'. How do I sort this table, assuming the basis for ordering is the last whole number of the string, regardless of what the character

Convert bytea to double precision in PostgreSQL

安稳与你 提交于 2019-12-23 09:39:47
问题 I have a database where one of the tables stores a blob ( bytea ) of all kinds of generic data collected from another system. The bytea field can have anything in it. In order to know how to interpret the data, the table also has a format field. I wrote a Java application to read the bytea field from the database as a byte[] and then I can easily convert it to double[] or int[] or whatever the format field says by using ByteBuffer and the various views ( DoubleBuffer , IntBuffer , etc.). Now

Hibernate postgres bytea retrieval issue

帅比萌擦擦* 提交于 2019-12-13 12:15:53
问题 I am using Hibernate 4.0 to store jpegs into postgres 9.1.4 (jdbc is postgresql-9.1-901.jdbc4.jar) bytea column(byte[] is the hibernate entity, without extra type def). The hibernate storing process works fine because I can use Database tools to dump the bytea column and still get the jpegs. It is basically: In the managedBean byte [] bytes; bytes = IOUtils.toByteArray(file.getInputstream()); entity.setImage(bytes); At this point, the bytes look like [-1, -40, -1, -32, 0, 16, 74, 70, ...]

phoenix elixir binary data image

 ̄綄美尐妖づ 提交于 2019-12-12 03:25:25
问题 Im using the phoenix framework to create a webpage and created an upload form to give the user the possiblity to upload a profil picture. def update(conn, %{"id" => id, "user" => %{"photo" => file}}) do if(File.exists?(file.path)) do case File.read(file.path) do {:ok, body} -> data = IO.iodata_to_binary(body) changeset = Whiteboard.File.changeset(%Whiteboard.File{}, %{user_id: currentuser.id, name: file.filename , data: data}) so that works and the binary data is in the database as bytea

PostgreSQL - How to insert Base64 images strings into a BYTEA column?

这一生的挚爱 提交于 2019-12-11 12:12:25
问题 I have the following SQL: CREATE TABLE Documents ( Id INT NOT NULL, UserId INT NOT NULL, Label CHARACTER VARYING(220) NOT NULL, Image BYTEA NOT NULL, PRIMARY Key(Id), FOREIGN KEY (UserId) REFERENCES Users(Id) ); I want to know, How should I have to insert the Base64 image into the table. The Base64 string comes from a Buffer from after getting the image using the fs module on Node.js. I'm attempting to insert the image using raw queries of Sequelize, but I have not found proper information on

Retrieving image from postgresql database using Yii2 (php)

做~自己de王妃 提交于 2019-12-11 04:35:41
问题 We have a problem retrieving uploaded image from postgres database with yii2 we store image with that way to the db: $data = pg_escape_bytea(file_get_contents($model->CheckIfAvatarExists(Yii::$app->user->identity->username))); $profile->passphoto = new Expression("'{$data}'"); $profile->save(); stores image perfectly but when we try to display image, it is not working: header('Content-type: image/png'); echo pg_unescape_bytea( $profile->passphoto); I think the big problem is data after

How to download bytea column as file using Java

≡放荡痞女 提交于 2019-12-10 11:46:25
问题 I want to download files stored in bytea format using java. I don't have superuser privileges. Using the code below I download the hex encoded file and convert it to pdf but the converted pdf is damaged whereas if I copy using \copy function(cannot use in java) via terminal, downloading process works smoothly. String sql = "(SELECT encode(f,'hex') FROM test_pdf where id='2' LIMIT 1)"; System.out.println(sql); CopyManager copyManager = new CopyManager((BaseConnection) conn); FileWriter filew =

PostgreSQL load images to DB

五迷三道 提交于 2019-12-10 11:18:08
问题 I've already know how to store images in DB, just use bytea type in my table And I've already can save images to DB via code in my project .net Core, I've just getting image by url and saving like there: using (HttpResponseMessage res = await client.GetAsync(photo_url)) using (HttpContent content = res.Content) { byte[] imageByte = await content.ReadAsByteArrayAsync(); using (NpgsqlConnection conn = new NpgsqlConnection("ConnectionString")) { conn.Open(); using (NpgsqlTransaction tran = conn

How to download bytea column as file using Java

♀尐吖头ヾ 提交于 2019-12-08 12:53:41
I want to download files stored in bytea format using java. I don't have superuser privileges. Using the code below I download the hex encoded file and convert it to pdf but the converted pdf is damaged whereas if I copy using \copy function(cannot use in java) via terminal, downloading process works smoothly. String sql = "(SELECT encode(f,'hex') FROM test_pdf where id='2' LIMIT 1)"; System.out.println(sql); CopyManager copyManager = new CopyManager((BaseConnection) conn); FileWriter filew = new FileWriter("/home/sourabh/image.hex"); copyManager.copyOut("COPY "+sql+" TO STDOUT ", filew );`