Could someone post a full example of using SQL & bytea to store/retrieve image data

From: Reid Thompson <reid(dot)thompson(at)ateb(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Could someone post a full example of using SQL & bytea to store/retrieve image data
Date: 2002-10-31 14:45:10
Message-ID: 3DC141F6.7080204@ateb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Say I have a jpg image at /tmp/junk/thisimage.jpg, and I wish to use the
ecpg preprocessor. Can someone post an example of the embedded SQL
required to store/retrieve said image?

Assuming CREATE TABLE images (
image_name VARCHAR,
binary_image bytea
);

Is special handling required, or can I:
assuming appropriate prior declarations for variables
assuming char buffer name_buffer contains the image name(thisimage.jpg)
assuming char buffer image_buffer contains the image binary data

EXEC SQL INSERT INTO images(image_name, binary_image) VALUES
(name_buffer, image_buffer);
(should name_buffer/image_buffer be :name_buffer/:image_buffer ?)

EXEC SQL SELECT binary_image INTO :image_buffer FROM images WHERE
image_name = 'thisimage.jpg';

thanks,
reid

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2002-10-31 14:54:02 setuid for defaults, constraints and triggers (Was: What user to [sic] defaults execute as?)
Previous Message Fernando Nasser 2002-10-31 14:44:50 Re: Can't start rhdb-admin