PostgreSQL

Скачать в pdf «PostgreSQL»


Figure 9.5 shows a query inserting values into arrayjest plus several queries selecting data from this table. Brackets are used to access individual array elements.


Any data type can be used as an array. If you need to frequently access or update individual elements of the array, use separate columns or tables rather than arrays.

9.8    Large Objects (BLOBs)


PostgreSQL cannot store values of more than several thousand bytes using the data types discussed so far, nor can binary data be easily entered within single quotes. Instead, large objects—also called Binary Large Objects or BLOBs—are used to store very large values and binary data.


test=> INSERT INTO array_test VALUES


test(>


test(>


test(>


test(> );


INSERT 52694 1


test=> SELECT * FROM array_test; coll    I co12    I


————-+—————+——-


{1,2,3,4,5}    |    {{1,2},{3,4}}    |    (({I,:


(1 row)


(


‘{1,2,3,4,5}’,


‘{{1,2},{3,4}}’, ‘{{{1,2},{3,4}},{{5,6}, {7,8}}}


col3


,{3,4}},{{5,6},{7,8}}}


test=> SELECT col1[4] FROM array_test; col1


4


(1 row)


test=> SELECT col2[2][1] FROM array_test; col2


3


(1 row)


test=> SELECT col3[1][2][2] FROM array_test; col3


4


(1 row)


Figure 9.5: Using arrays


test=> CREATE TABLE fruit (name CHAR(30), image OID);


CREATE


test=> INSERT INTO fruit


test-> VALUES (‘peach’, lo_import(‘/usr/images/peach.jpg’)); INSERT 27111 1


test=> SELECT lo_export(fruit.image, ‘/tmp/outimage.jpg’) test-> FROM fruit test-> WHERE name = ‘peach’; lo_export


1


(1 row)


test=> SELECT lo_unlink(fruit.image) FROM fruit; lo unlink


1


(1 row)


Figure 9.6: Using large images

Скачать в pdf «PostgreSQL»