473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

bytea

when bytea, text, and varchar(no limit entered) columns are used, do
they ALWAYS use an extra table/file? Or do they only do it after a
certain size of input?

Also, if I wanted to put a *.pdf file in a bytea column, what functions
do I use to escape any characters in it?

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #1
7 4429
> Also, if I wanted to put a *.pdf file in a bytea column, what functions
do I use to escape any characters in it?
What programming language are you using?

In Perl, you do something like:

$sth->bind_param(1, $file_data, DBI::SQL_BINARY); #DBI::SQL_BINARY is
deprecated, but it works

In php you do:

$file_data = pg_escape_bytea($file_data);

$db->query("insert into blah(blahh) values ('${file_data}'::bytea);

To retrieve the info in Perl, it's just a regular fetchrow()

my ($file_data) = $sth->fetchrow();

In php, you have to run stripcslashes() on the data.

list($file_data) = $query->fetchrow();
$file_data = stripcslashes($file_data);

Jon


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #2
I forgot, please CC me, I am on digest.
Dennis Gearon wrote:
when bytea, text, and varchar(no limit entered) columns are used, do
they ALWAYS use an extra table/file? Or do they only do it after a
certain size of input?

Also, if I wanted to put a *.pdf file in a bytea column, what
functions do I use to escape any characters in it?

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #3
On Tue, May 11, 2004 at 09:30:15AM -0700, Jonathan Bartlett wrote:
Also, if I wanted to put a *.pdf file in a bytea column, what functions
do I use to escape any characters in it?


What programming language are you using?


Apparently if you are using C and libpq, you can use the version 3
protocol functions to send binary data without having to escape it. I
haven't done it though so I may be wrong, but if I'm right please
somebody tell me because I usually recommend this :-)

Also if it works it would be useful to update the Perl/PHP/etc
interfaces to use it.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"El sudor es la mejor cura para un pensamiento enfermo" (Bardia)

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #4
Thanks for all the answers everybody, but I need to know also an answer
to the other question:

Does the bytea make its own files automatically for large objects?

Also, how about backups with tables having bytea columns.?

Jonathan Bartlett wrote:
Also, if I wanted to put a *.pdf file in a bytea column, what functions
do I use to escape any characters in it?


What programming language are you using?

In Perl, you do something like:

$sth->bind_param(1, $file_data, DBI::SQL_BINARY); #DBI::SQL_BINARY is
deprecated, but it works

In php you do:

$file_data = pg_escape_bytea($file_data);

$db->query("insert into blah(blahh) values ('${file_data}'::bytea);

To retrieve the info in Perl, it's just a regular fetchrow()

my ($file_data) = $sth->fetchrow();

In php, you have to run stripcslashes() on the data.

list($file_data) = $query->fetchrow();
$file_data = stripcslashes($file_data);

Jon

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #5
On Tue, 11 May 2004, Dennis Gearon wrote:
Thanks for all the answers everybody, but I need to know also an answer
to the other question:

Does the bytea make its own files automatically for large objects?
Bytea doesn't use large objects, which are kind of an artifact left over
from the days of the 8k row limit. They use what are called "toast"
tables. Toast tables allow for text/varchar/bytea types to overflow from
the base table as needed to occupy up to ~2 gigabytes of drive space per
field max. Note that I'm pretty sure no one's really tried to put 2 gig
in one field, as that would probably take quite some time, and I'm not
sure how well most clients are gonna handle getting back a row with a 2
gig field in it. :-)

And yes, toasting is fully automatic. Just insert a large
text/varchar/bytea field and the database does the rest. which is why
they are generally recommended over using large objects, which require
specialized handling.
Also, how about backups with tables having bytea columns.?


Just like any other field. pg_dump will escape them as needed to make a
usable backup.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #6
On Tue, May 11, 2004 at 11:50:06AM -0700, Dennis Gearon wrote:
Thanks for all the answers everybody, but I need to know also an answer
to the other question:

Does the bytea make its own files automatically for large objects?
No, they are stored in tables.
Also, how about backups with tables having bytea columns.?


What about them? They should work just fine.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"La vida es para el que se aventura"

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #7
> Does the bytea make its own files automatically for large objects?

I do not believe so. You'd have to check with someone else for sure,
though.
Also, how about backups with tables having bytea columns.?


Regular pg_dump handles bytea columns just fine.

Jon
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mPath Records | last post by:
Hello, I hope someone can help me with this problem - I'm getting nowhere fast and have been working on it for a week. All I'm trying to do is upload an image, store the image in a bytea...
48
by: Edwin Quijada | last post by:
Hi !! Everybody I am developing app using Delphi and I have a question: I have to save pictures into my database. Each picture has 20 o 30k aprox. What is the way more optimus? That 's table will...
1
by: Baldur Norddahl | last post by:
Hi, I need to do something like this: select * from sms where message ilike 'foo%'; Message is a bytea field with UTF-8 content. The charset is actually not important for me, it would be...
2
by: Alvar Freude | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I want to change a column from text to bytea; since it seems that alter table can't change the column type, i have to add a temporary column...
0
by: Alvar Freude | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, the following I posted already on pgsql-bugs -- perhaps someone has a good workaround or fix or can say me that I'm wrong? There seems to...
4
by: David Garamond | last post by:
May I request that connectby() supports BYTEA keys too? My keys are GUID (16-byte stored in BYTEA). In this case, branch_delim does not make sense because the keys should be fixed-length anyway,...
7
by: C G | last post by:
Dear All, What's the best way to store jpgs in postgresql to use in a web page? I tried to use large objects, but how would you extract them from a table to be viewed in a web-page without...
0
by: Peter Wang | last post by:
I have a function and am using cursor. All the columns I select in the cursor clause are BYTEA datatype. I need to compare the after-fetch-value for two BYTEA columns which is temp2 and temp3...
4
by: Jerry LeVan | last post by:
Hi, I am adding image and large object support in my Cocoa postgresql browser. Are there going to be any enhanced bytea support functions coming along? It seems sorta silly to have to write...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.