package postgresql

  1. Overview
  2. Docs

Client-interface to the PostgreSQL database.

Please learn about more details in the database documentation!

Types

type oid = int

Object ID (= Postgresql type of an object)

type large_object

Handle for large objects

module FFormat : sig ... end

Type of field formats

type ftype =
  1. | BOOL
  2. | BYTEA
  3. | CHAR
  4. | NAME
  5. | INT8
  6. | INT2
  7. | INT2VECTOR
  8. | INT4
  9. | REGPROC
  10. | TEXT
  11. | OID
  12. | TID
  13. | XID
  14. | CID
  15. | OIDVECTOR
  16. | JSON
  17. | POINT
  18. | LSEG
  19. | PATH
  20. | BOX
  21. | POLYGON
  22. | LINE
  23. | FLOAT4
  24. | FLOAT8
  25. | ABSTIME
  26. | RELTIME
  27. | TINTERVAL
  28. | UNKNOWN
  29. | CIRCLE
  30. | CASH
  31. | MACADDR
  32. | INET
  33. | CIDR
  34. | ACLITEM
  35. | BPCHAR
  36. | VARCHAR
  37. | DATE
  38. | TIME
  39. | TIMESTAMP
  40. | TIMESTAMPTZ
  41. | INTERVAL
  42. | TIMETZ
  43. | BIT
  44. | VARBIT
  45. | NUMERIC
  46. | REFCURSOR
  47. | REGPROCEDURE
  48. | REGOPER
  49. | REGOPERATOR
  50. | REGCLASS
  51. | REGTYPE
  52. | RECORD
  53. | CSTRING
  54. | ANY
  55. | ANYARRAY
  56. | VOID
  57. | TRIGGER
  58. | LANGUAGE_HANDLER
  59. | INTERNAL
  60. | OPAQUE
  61. | ANYELEMENT
  62. | JSONB

Type of fields

module Error_field : sig ... end
module Error_code : sig ... end
type result_status =
  1. | Empty_query
    (*

    String sent to the backend was empty

    *)
  2. | Command_ok
    (*

    Successful completion of a command returning no data

    *)
  3. | Tuples_ok
    (*

    The query successfully executed

    *)
  4. | Copy_out
    (*

    Copy Out (from server) data transfer started

    *)
  5. | Copy_in
    (*

    Copy In (to server) data transfer started

    *)
  6. | Bad_response
    (*

    The server's response was not understood

    *)
  7. | Nonfatal_error
  8. | Fatal_error
  9. | Copy_both
  10. | Single_tuple
    (*

    One tuple of a result set (set_single_row_mode)

    *)

Status of command/query results

type put_copy_result =
  1. | Put_copy_queued
    (*

    Data queued

    *)
  2. | Put_copy_not_queued
    (*

    Data not queued due to full bufffers (async only)

    *)
  3. | Put_copy_error
    (*

    Copying failed, see #error_message for details

    *)

Result of put_copy_data and put_copy_end

type get_copy_result =
  1. | Get_copy_data of string
    (*

    Data corresponding to one row is returned

    *)
  2. | Get_copy_wait
    (*

    The next row is still being received (async only); wait for read-only, call consume_input, and try again

    *)
  3. | Get_copy_end
    (*

    All data has been successfully retrieved

    *)
  4. | Get_copy_error
    (*

    Copying failed, see #error_message for details

    *)

Result of get_copy_data

type getline_result =
  1. | EOF
    (*

    End of input reached

    *)
  2. | LineRead
    (*

    Entire line has been read

    *)
  3. | BufFull
    (*

    Buffer full but terminating newline not encountered

    *)

Result of getline

type getline_async_result =
  1. | EndOfData
    (*

    End-of-copy-data marker recognized

    *)
  2. | NoData
    (*

    No data available

    *)
  3. | DataRead of int
    (*

    DataRead n indicates n bytes of read data

    *)
  4. | PartDataRead of int
    (*

    Like DataRead, but data only partially read

    *)

Result of getline_async

type seek_cmd =
  1. | SEEK_SET
    (*

    Seek from start of large object

    *)
  2. | SEEK_CUR
    (*

    Seek from current read/write position of large object

    *)
  3. | SEEK_END
    (*

    Seek from end of large object

    *)

Seek command ("whence")

Exceptions and error handling

type error =
  1. | Field_out_of_range of int * int
  2. | Tuple_out_of_range of int * int
  3. | Binary
  4. | Connection_failure of string
  5. | Unexpected_status of result_status * string * result_status list
  6. | Cancel_failure of string

Kinds of exceptions:

Field_out_of_range (i, n) - access to field i not within range n Tuple_out_of_range (i, n) - access to tuple i not within range n Binary - result consists of binary tuple data Connection_failure msg - connection failed due to reason msg Unexpected_status (stat, msg, expected) - result status stat was not in expected due to error msg

exception Error of error

Error error indicates an error

val string_of_error : error -> string

string_of_error error convert error to a human-readable message

exception Oid of oid

Oid oid conversion from an oid to an ftype encountered an unknown oid

Utility functions

val unescape_bytea : string -> string

unescape_bytea str unescapes binary string str. This function supports the new hex format for encoding bytea strings (introduced in Postgresql 9.0) even if the local libpq library is from an older version.

val ftype_of_oid : oid -> ftype

ftype_of_oid oid converts oid to an ftype.

val oid_of_ftype : ftype -> oid

oid_of_ftype ftype converts ftype to an oid.

val string_of_ftype : ftype -> string

string_of_ftype ftype converts ftype to a string.

val ftype_of_string : string -> ftype

string_of_ftype ftype converts string to a ftype.

Handling results of commands and queries

val result_status : result_status -> string

result_status stat convert status stat to a human-readable message

val invalid_oid : oid

invalid_oid invalid Oid.

Query parameters

val null : string

null can be used as an element of the optional argument parameters passed to the exec or send_query method to indicate a NULL value.

class type result = object ... end

Class type of query results.

Handling database connections

type connection_status =
  1. | Ok
  2. | Bad
  3. | Connection_started
  4. | Connection_made
  5. | Connection_awaiting_response
  6. | Connection_auth_ok
  7. | Connection_setenv
  8. | Connection_ssl_startup

Status of a connection

type polling_status =
  1. | Polling_failed
  2. | Polling_reading
  3. | Polling_writing
  4. | Polling_ok

Polling status used while establishing a connection asynchronously.

type flush_status =
  1. | Successful
  2. | Data_left_to_send

Result of a call to flush on nonblocking connections.

type conninfo_option = {
  1. cio_keyword : string;
    (*

    Keyword of option

    *)
  2. cio_envvar : string option;
    (*

    Fallback environment variable name

    *)
  3. cio_compiled : string option;
    (*

    Fallback compiled in default value

    *)
  4. cio_val : string option;
    (*

    Current value of option, or NULL

    *)
  5. cio_label : string;
    (*

    Label for field in connect dialog

    *)
  6. cio_dispchar : string;
    (*

    Character to display for this field in dialog

    *)
  7. cio_dispsize : int;
    (*

    Field size in characters for dialog

    *)
}

Record of connection options

module Notification : sig ... end

Type of asynchronous notifications

val conndefaults : unit -> conninfo_option array

conndefaults ()

  • returns

    array of all records of type conninfo_option

class connection : ?host:string -> ?hostaddr:string -> ?port:string -> ?dbname:string -> ?user: string -> ?password:string -> ?options:string -> ?tty:string -> ?requiressl: string -> ?conninfo:string -> ?startonly:bool -> unit -> object ... end

Class of connections.

OCaml

Innovation. Community. Security.