~ubuntu-branches/ubuntu/trusty/postgresql-9.3/trusty-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Client Interfaces</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.3.13 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Large Objects"
HREF="largeobjects.html"><LINK
REL="PREVIOUS"
TITLE="Implementation Features"
HREF="lo-implementation.html"><LINK
REL="NEXT"
TITLE="Server-side Functions"
HREF="lo-funcs.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2016-05-09T21:13:26"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.3.13 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Implementation Features"
HREF="lo-implementation.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="largeobjects.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 32. Large Objects</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Server-side Functions"
HREF="lo-funcs.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="LO-INTERFACES"
>32.3. Client Interfaces</A
></H1
><P
>    This section describes the facilities that
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>'s <SPAN
CLASS="APPLICATION"
>libpq</SPAN
>
    client interface library provides for accessing large objects.
    The <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> large object interface is
    modeled after the <ACRONYM
CLASS="ACRONYM"
>Unix</ACRONYM
> file-system interface, with
    analogues of <CODE
CLASS="FUNCTION"
>open</CODE
>,  <CODE
CLASS="FUNCTION"
>read</CODE
>,
    <CODE
CLASS="FUNCTION"
>write</CODE
>,
    <CODE
CLASS="FUNCTION"
>lseek</CODE
>, etc.
   </P
><P
>    All large object manipulation using these functions
    <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>must</I
></SPAN
> take place within an SQL transaction block,
    since large object file descriptors are only valid for the duration of
    a transaction.
   </P
><P
>    If an error occurs while executing any one of these functions, the
    function will return an otherwise-impossible value, typically 0 or -1.
    A message describing the error is stored in the connection object and
    can be retrieved with <CODE
CLASS="FUNCTION"
>PQerrorMessage</CODE
>.
   </P
><P
>    Client applications that use these functions should include the header file
    <TT
CLASS="FILENAME"
>libpq/libpq-fs.h</TT
> and link with the
    <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> library.
   </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-CREATE"
>32.3.1. Creating a Large Object</A
></H2
><P
>     
     The function
</P><PRE
CLASS="SYNOPSIS"
>Oid lo_creat(PGconn *conn, int mode);</PRE
><P>
     creates a new large object.
     The return value is the OID that was assigned to the new large object,
     or <TT
CLASS="SYMBOL"
>InvalidOid</TT
> (zero) on failure.

     <TT
CLASS="REPLACEABLE"
><I
>mode</I
></TT
> is unused and
     ignored as of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 8.1; however, for
     backward compatibility with earlier releases it is best to
     set it to <TT
CLASS="SYMBOL"
>INV_READ</TT
>, <TT
CLASS="SYMBOL"
>INV_WRITE</TT
>,
     or <TT
CLASS="SYMBOL"
>INV_READ</TT
> <TT
CLASS="LITERAL"
>|</TT
> <TT
CLASS="SYMBOL"
>INV_WRITE</TT
>.
     (These symbolic constants are defined
     in the header file <TT
CLASS="FILENAME"
>libpq/libpq-fs.h</TT
>.)
    </P
><P
>     An example:
</P><PRE
CLASS="PROGRAMLISTING"
>inv_oid = lo_creat(conn, INV_READ|INV_WRITE);</PRE
><P>
    </P
><P
>     
     The function
</P><PRE
CLASS="SYNOPSIS"
>Oid lo_create(PGconn *conn, Oid lobjId);</PRE
><P>
     also creates a new large object.  The OID to be assigned can be
     specified by <TT
CLASS="REPLACEABLE"
><I
>lobjId</I
></TT
>;
     if so, failure occurs if that OID is already in use for some large
     object.  If <TT
CLASS="REPLACEABLE"
><I
>lobjId</I
></TT
>
     is <TT
CLASS="SYMBOL"
>InvalidOid</TT
> (zero) then <CODE
CLASS="FUNCTION"
>lo_create</CODE
> assigns an unused
     OID (this is the same behavior as <CODE
CLASS="FUNCTION"
>lo_creat</CODE
>).
     The return value is the OID that was assigned to the new large object,
     or <TT
CLASS="SYMBOL"
>InvalidOid</TT
> (zero) on failure.
    </P
><P
>     <CODE
CLASS="FUNCTION"
>lo_create</CODE
> is new as of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
     8.1; if this function is run against an older server version, it will
     fail and return <TT
CLASS="SYMBOL"
>InvalidOid</TT
>.
    </P
><P
>     An example:
</P><PRE
CLASS="PROGRAMLISTING"
>inv_oid = lo_create(conn, desired_oid);</PRE
><P>
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-IMPORT"
>32.3.2. Importing a Large Object</A
></H2
><P
>     
     To import an operating system file as a large object, call
</P><PRE
CLASS="SYNOPSIS"
>Oid lo_import(PGconn *conn, const char *filename);</PRE
><P>
     <TT
CLASS="REPLACEABLE"
><I
>filename</I
></TT
>
     specifies the operating system name of
     the file to be imported as a large object.
     The return value is the OID that was assigned to the new large object,
     or <TT
CLASS="SYMBOL"
>InvalidOid</TT
> (zero) on failure.
     Note that the file is read by the client interface library, not by
     the server; so it must exist in the client file system and be readable
     by the client application.
    </P
><P
>     
     The function
</P><PRE
CLASS="SYNOPSIS"
>Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);</PRE
><P>
     also imports a new large object.  The OID to be assigned can be
     specified by <TT
CLASS="REPLACEABLE"
><I
>lobjId</I
></TT
>;
     if so, failure occurs if that OID is already in use for some large
     object.  If <TT
CLASS="REPLACEABLE"
><I
>lobjId</I
></TT
>
     is <TT
CLASS="SYMBOL"
>InvalidOid</TT
> (zero) then <CODE
CLASS="FUNCTION"
>lo_import_with_oid</CODE
> assigns an unused
     OID (this is the same behavior as <CODE
CLASS="FUNCTION"
>lo_import</CODE
>).
     The return value is the OID that was assigned to the new large object,
     or <TT
CLASS="SYMBOL"
>InvalidOid</TT
> (zero) on failure.
    </P
><P
>     <CODE
CLASS="FUNCTION"
>lo_import_with_oid</CODE
> is new as of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
     8.4 and uses <CODE
CLASS="FUNCTION"
>lo_create</CODE
> internally which is new in 8.1; if this function is run against 8.0 or before, it will
     fail and return <TT
CLASS="SYMBOL"
>InvalidOid</TT
>.
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-EXPORT"
>32.3.3. Exporting a Large Object</A
></H2
><P
>     
     To export a large object
     into an operating system file, call
</P><PRE
CLASS="SYNOPSIS"
>int lo_export(PGconn *conn, Oid lobjId, const char *filename);</PRE
><P>
     The <TT
CLASS="PARAMETER"
>lobjId</TT
> argument specifies the OID of the large
     object to export and the <TT
CLASS="PARAMETER"
>filename</TT
> argument
     specifies the operating system name of the file.  Note that the file is
     written by the client interface library, not by the server.  Returns 1
     on success, -1 on failure.
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-OPEN"
>32.3.4. Opening an Existing Large Object</A
></H2
><P
>     
     To open an existing large object for reading or writing, call
</P><PRE
CLASS="SYNOPSIS"
>int lo_open(PGconn *conn, Oid lobjId, int mode);</PRE
><P>
     The <TT
CLASS="PARAMETER"
>lobjId</TT
> argument specifies the OID of the large
     object to open.   The <TT
CLASS="PARAMETER"
>mode</TT
> bits control whether the
     object is opened for reading (<TT
CLASS="SYMBOL"
>INV_READ</TT
>), writing
     (<TT
CLASS="SYMBOL"
>INV_WRITE</TT
>), or both.
     (These symbolic constants are defined
     in the header file <TT
CLASS="FILENAME"
>libpq/libpq-fs.h</TT
>.)
     <CODE
CLASS="FUNCTION"
>lo_open</CODE
> returns a (non-negative) large object
     descriptor for later use in <CODE
CLASS="FUNCTION"
>lo_read</CODE
>,
     <CODE
CLASS="FUNCTION"
>lo_write</CODE
>, <CODE
CLASS="FUNCTION"
>lo_lseek</CODE
>,
     <CODE
CLASS="FUNCTION"
>lo_lseek64</CODE
>, <CODE
CLASS="FUNCTION"
>lo_tell</CODE
>,
     <CODE
CLASS="FUNCTION"
>lo_tell64</CODE
>, <CODE
CLASS="FUNCTION"
>lo_truncate</CODE
>,
     <CODE
CLASS="FUNCTION"
>lo_truncate64</CODE
>, and <CODE
CLASS="FUNCTION"
>lo_close</CODE
>.
     The descriptor is only valid for
     the duration of the current transaction.
     On failure, -1 is returned.
    </P
><P
>     The server currently does not distinguish between modes
     <TT
CLASS="SYMBOL"
>INV_WRITE</TT
> and <TT
CLASS="SYMBOL"
>INV_READ</TT
> <TT
CLASS="LITERAL"
>|</TT
>
     <TT
CLASS="SYMBOL"
>INV_WRITE</TT
>: you are allowed to read from the descriptor
     in either case.  However there is a significant difference between
     these modes and <TT
CLASS="SYMBOL"
>INV_READ</TT
> alone: with <TT
CLASS="SYMBOL"
>INV_READ</TT
>
     you cannot write on the descriptor, and the data read from it will
     reflect the contents of the large object at the time of the transaction
     snapshot that was active when <CODE
CLASS="FUNCTION"
>lo_open</CODE
> was executed,
     regardless of later writes by this or other transactions.  Reading
     from a descriptor opened with <TT
CLASS="SYMBOL"
>INV_WRITE</TT
> returns
     data that reflects all writes of other committed transactions as well
     as writes of the current transaction.  This is similar to the behavior
     of <TT
CLASS="LITERAL"
>REPEATABLE READ</TT
> versus <TT
CLASS="LITERAL"
>READ COMMITTED</TT
> transaction
     modes for ordinary SQL <TT
CLASS="COMMAND"
>SELECT</TT
> commands.
    </P
><P
>     An example:
</P><PRE
CLASS="PROGRAMLISTING"
>inv_fd = lo_open(conn, inv_oid, INV_READ|INV_WRITE);</PRE
><P>
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-WRITE"
>32.3.5. Writing Data to a Large Object</A
></H2
><P
>     
     The function
</P><PRE
CLASS="SYNOPSIS"
>int lo_write(PGconn *conn, int fd, const char *buf, size_t len);</PRE
><P>
     writes <TT
CLASS="PARAMETER"
>len</TT
> bytes from <TT
CLASS="PARAMETER"
>buf</TT
>
     (which must be of size <TT
CLASS="PARAMETER"
>len</TT
>) to large object
     descriptor <TT
CLASS="PARAMETER"
>fd</TT
>.  The <TT
CLASS="PARAMETER"
>fd</TT
> argument must
     have been returned by a previous <CODE
CLASS="FUNCTION"
>lo_open</CODE
>.  The
     number of bytes actually written is returned (in the current
     implementation, this will always equal <TT
CLASS="PARAMETER"
>len</TT
> unless
     there is an error).  In the event of an error, the return value is -1.</P
><P
>     Although the <TT
CLASS="PARAMETER"
>len</TT
> parameter is declared as
     <TT
CLASS="TYPE"
>size_t</TT
>, this function will reject length values larger than
     <TT
CLASS="LITERAL"
>INT_MAX</TT
>.  In practice, it's best to transfer data in chunks
     of at most a few megabytes anyway.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-READ"
>32.3.6. Reading Data from a Large Object</A
></H2
><P
>     
     The function
</P><PRE
CLASS="SYNOPSIS"
>int lo_read(PGconn *conn, int fd, char *buf, size_t len);</PRE
><P>
     reads up to <TT
CLASS="PARAMETER"
>len</TT
> bytes from large object descriptor
     <TT
CLASS="PARAMETER"
>fd</TT
> into <TT
CLASS="PARAMETER"
>buf</TT
> (which must be
     of size <TT
CLASS="PARAMETER"
>len</TT
>).  The <TT
CLASS="PARAMETER"
>fd</TT
>
     argument must have been returned by a previous
     <CODE
CLASS="FUNCTION"
>lo_open</CODE
>.  The number of bytes actually read is
     returned; this will be less than <TT
CLASS="PARAMETER"
>len</TT
> if the end of
     the large object is reached first.  In the event of an error, the return
     value is -1.</P
><P
>     Although the <TT
CLASS="PARAMETER"
>len</TT
> parameter is declared as
     <TT
CLASS="TYPE"
>size_t</TT
>, this function will reject length values larger than
     <TT
CLASS="LITERAL"
>INT_MAX</TT
>.  In practice, it's best to transfer data in chunks
     of at most a few megabytes anyway.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-SEEK"
>32.3.7. Seeking in a Large Object</A
></H2
><P
>     
     To change the current read or write location associated with a
     large object descriptor, call
</P><PRE
CLASS="SYNOPSIS"
>int lo_lseek(PGconn *conn, int fd, int offset, int whence);</PRE
><P>
     This function moves the
     current location pointer for the large object descriptor identified by
     <TT
CLASS="PARAMETER"
>fd</TT
> to the new location specified by
     <TT
CLASS="PARAMETER"
>offset</TT
>.  The valid values for <TT
CLASS="PARAMETER"
>whence</TT
>
     are <TT
CLASS="SYMBOL"
>SEEK_SET</TT
> (seek from object start),
     <TT
CLASS="SYMBOL"
>SEEK_CUR</TT
> (seek from current position), and
     <TT
CLASS="SYMBOL"
>SEEK_END</TT
> (seek from object end).  The return value is
     the new location pointer, or -1 on error.</P
><P
>     
     When dealing with large objects that might exceed 2GB in size,
     instead use
</P><PRE
CLASS="SYNOPSIS"
>pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);</PRE
><P>
     This function has the same behavior
     as <CODE
CLASS="FUNCTION"
>lo_lseek</CODE
>, but it can accept an
     <TT
CLASS="PARAMETER"
>offset</TT
> larger than 2GB and/or deliver a result larger
     than 2GB.
     Note that <CODE
CLASS="FUNCTION"
>lo_lseek</CODE
> will fail if the new location
     pointer would be greater than 2GB.</P
><P
>     <CODE
CLASS="FUNCTION"
>lo_lseek64</CODE
> is new as of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
     9.3.  If this function is run against an older server version, it will
     fail and return -1.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-TELL"
>32.3.8. Obtaining the Seek Position of a Large Object</A
></H2
><P
>     
     To obtain the current read or write location of a large object descriptor,
     call
</P><PRE
CLASS="SYNOPSIS"
>int lo_tell(PGconn *conn, int fd);</PRE
><P>
     If there is an error, the return value is -1.</P
><P
>     
     When dealing with large objects that might exceed 2GB in size,
     instead use
</P><PRE
CLASS="SYNOPSIS"
>pg_int64 lo_tell64(PGconn *conn, int fd);</PRE
><P>
     This function has the same behavior
     as <CODE
CLASS="FUNCTION"
>lo_tell</CODE
>, but it can deliver a result larger
     than 2GB.
     Note that <CODE
CLASS="FUNCTION"
>lo_tell</CODE
> will fail if the current
     read/write location is greater than 2GB.</P
><P
>     <CODE
CLASS="FUNCTION"
>lo_tell64</CODE
> is new as of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
     9.3.  If this function is run against an older server version, it will
     fail and return -1.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-TRUNCATE"
>32.3.9. Truncating a Large Object</A
></H2
><P
>     
     To truncate a large object to a given length, call
</P><PRE
CLASS="SYNOPSIS"
>int lo_truncate(PGcon *conn, int fd, size_t len);</PRE
><P>
     This function truncates the large object
     descriptor <TT
CLASS="PARAMETER"
>fd</TT
> to length <TT
CLASS="PARAMETER"
>len</TT
>.  The
     <TT
CLASS="PARAMETER"
>fd</TT
> argument must have been returned by a
     previous <CODE
CLASS="FUNCTION"
>lo_open</CODE
>.  If <TT
CLASS="PARAMETER"
>len</TT
> is
     greater than the large object's current length, the large object
     is extended to the specified length with null bytes ('\0').
     On success, <CODE
CLASS="FUNCTION"
>lo_truncate</CODE
> returns
     zero.  On error, the return value is -1.</P
><P
>     The read/write location associated with the descriptor
     <TT
CLASS="PARAMETER"
>fd</TT
> is not changed.</P
><P
>     Although the <TT
CLASS="PARAMETER"
>len</TT
> parameter is declared as
     <TT
CLASS="TYPE"
>size_t</TT
>, <CODE
CLASS="FUNCTION"
>lo_truncate</CODE
> will reject length
     values larger than <TT
CLASS="LITERAL"
>INT_MAX</TT
>.</P
><P
>     
     When dealing with large objects that might exceed 2GB in size,
     instead use
</P><PRE
CLASS="SYNOPSIS"
>int lo_truncate64(PGcon *conn, int fd, pg_int64 len);</PRE
><P>
     This function has the same
     behavior as <CODE
CLASS="FUNCTION"
>lo_truncate</CODE
>, but it can accept a
     <TT
CLASS="PARAMETER"
>len</TT
> value exceeding 2GB.</P
><P
>     <CODE
CLASS="FUNCTION"
>lo_truncate</CODE
> is new as of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
     8.3; if this function is run against an older server version, it will
     fail and return -1.</P
><P
>     <CODE
CLASS="FUNCTION"
>lo_truncate64</CODE
> is new as of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
     9.3; if this function is run against an older server version, it will
     fail and return -1.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-CLOSE"
>32.3.10. Closing a Large Object Descriptor</A
></H2
><P
>     
     A large object descriptor can be closed by calling
</P><PRE
CLASS="SYNOPSIS"
>int lo_close(PGconn *conn, int fd);</PRE
><P>
     where <TT
CLASS="PARAMETER"
>fd</TT
> is a
     large object descriptor returned by <CODE
CLASS="FUNCTION"
>lo_open</CODE
>.
     On success, <CODE
CLASS="FUNCTION"
>lo_close</CODE
> returns zero.  On
     error, the return value is -1.</P
><P
>     Any large  object  descriptors that remain open at the end of a
     transaction will be closed automatically.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="LO-UNLINK"
>32.3.11. Removing a Large Object</A
></H2
><P
>     
     To remove a large object from the database, call
</P><PRE
CLASS="SYNOPSIS"
>int lo_unlink(PGconn *conn, Oid lobjId);</PRE
><P>
     The <TT
CLASS="PARAMETER"
>lobjId</TT
> argument specifies the OID of the
     large object to remove.  Returns 1 if successful, -1 on failure.
    </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="lo-implementation.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="lo-funcs.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Implementation Features</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="largeobjects.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Server-side Functions</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>