PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2013, 11:26 AM
dokhebi dokhebi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 23 dokhebi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 17 m 50 sec
Reputation Power: 0
Update bytea column in existing row

I have a table with a bytea column where I want to store an Encapsulated PostScript file so I don't have to place it on every machine that accesses the database. I have not found a useful method for for loading the EPS file into the column. I though it would be as easy as:

UPDATE table
SET epsfile = 'filename.eps'
WHERE tablekey = 1;

My temporary solution is a column with the file name and the actual file in the directory where the application (a Perl script) lives.

I understand that there will be a performance hit from copying the file (1 Mb in size) over the network every time the application needs the file but it's easier to do that then make sure the current version of the file is installed on every machine that needs it.

I looked at using a Perl script to load it but the PostScript::Simple::EPS module doesn't include an option for putting the contents of the file in a scalar.

Reply With Quote
  #2  
Old January 28th, 2013, 07:01 PM
dokhebi dokhebi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 23 dokhebi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 17 m 50 sec
Reputation Power: 0
It looks like I can answer my own question. For those who are interested, it's looks like this (in Perl):

Code:
use DBI;
$dbh = DBI->connect("DBI:Pg:dbname=postgres;host=localhost;port=5432", "postgres", "postgres");
$sth = dbh->prepare("UPDATE table SET column = (?::bytea) WHERE key = ?");

$sth->bind_param(1, $bindata, { pg_type => DBD::Pg::PG_BYTEA});
$sth->bind_param(2, $key);
$sth->execute;


This is basic but it gets the idea across. Remember to check for errors!

Reply With Quote
  #3  
Old January 29th, 2013, 12:31 PM
dokhebi dokhebi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 23 dokhebi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 17 m 50 sec
Reputation Power: 0
I had to edit my response because I got the method wrong for binding the parameters. I had "bind_column" but meant "bind_param." I'm sorry if this confused anyone.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Update bytea column in existing row

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap