Python Connector for PostgreSQL

Module additions - Python Connector for PostgreSQL

Module additions

The module provides several additional constructors and type objects for handling PostgreSQL-specific database types.

Constructors

Numeric(weight, scale, sign, digits|value)

Creates an object that holds a number with a very large number of digits.

Arguments

weight, scale, sign, digits

Corresponding values for the numeric object attributes.

value

A value of type str, int, float, or a numeric object.

Return value

Returns a numeric object.

Remarks

The value argument can also contain special values Infinity, -Infinity, and NaN (or their string representations). These are adapted from the IEEE 754 standard, and represent the positive infinity, negative infinity, and not-a-number, respectively.

Point(x, y|value)

Creates an object that holds coordinates of a point on a plane.

Arguments

x, y

Values of type int or float that specify the coordinates of the point.

value

A string literal of form (x, y) wherex and y are the respective coordinates, or a point object.

Return value

Returns a point object.

Lseg(start, end|startx, starty, endx, endy|value)

Creates an object that holds information about a line segment.

Arguments

start, end

Values of type point that specify the endpoints of the segment.

startx, starty, endx, endy

Values of type int or float that specify the coordinates of the endpoints.

value

A string literal of form [(x1, y1), (x2, y2)] where (x1, y1) and (x2, y2) are the respective endpoints, or a lseg object.

Return value

Returns a lseg object.

Line(a, b, c|value)

Creates an object that holds information about a line.

Arguments

a, b, c

Values of type int or float that specify the coefficients of the linear equation ax + by + c = 0 that describes the line.

value

A string literal of form {a, b, c} where a, b, and c are the respective coefficients, or a line object.

Return value

Returns a line object.

Remarks

The a and b arguments must not both be zero.

Path(points|value)

Creates an object that holds an array of connected line segments.

Arguments

points

A list of point objects that specify the endpoints of the segments that form the path.

value

A string literal of form [(x1, y1), ..., (xn, yn)] where (xn, yn) are sequential endpoints of all the segments, or a path object.

Return value

Returns a path object.

Polygon(points|value)

Creates an object that holds information about a polygon.

Arguments

points

A list of point objects that specify the vertexes of the polygon.

value

A string literal of form ((x1, y1), ..., (xn, yn)) where (xn, yn) are sequential coordinates of all the vertexes of the polygon, or a polygon object.

Return value

Returns a polygon object.

Box(upperright, lowerleft|upperrightx, upperrighty, lowerleftx, lowerlefty|value)

Creates an object that holds information about the rectangle.

Arguments

upperright, lowerleft

Values of type point that specify the upper right and lower left corners of the rectangle.

upperrightx, upperrighty, lowerleftx, lowerlefty

Values of type int or float that specify the coordinates of the rectangle corners.

value

A string literal of form ((x1, y1), (x2, y2)) where (x1, y1) and (x2, y2) are coordinates of two opposite corners of the rectangle, or a box object.

Return value

Returns a box object.

Remarks

There are no strict requirements that the input values must be exactly upper right and lower left corners. Any two opposite corners can be supplied, but you should keep in mind that when saved into a database, the values will be reordered as needed to store the upper right and lower left corners, in that order. Therefore, on subsequent reading of the stored value, you may get an object that doesn't match the one that was written.

Circle(center, radius|centerx, centery, radius|value)

Creates an object that holds information about a circle.

Arguments

center

A value of type point that specifies the center point of the circle.

radius

A value of type int or float that specifies the radius of the circle.

centerx, centery, radius

Values of type int or float that specify coordinates of the center point of the circle and it's radius, respectively.

value

A string literal of form <(x, y), r> where x and y are the center point coordinates and r is the radius, or a circle object.

Return value

Returns a circle object.

Vector(item)

Creates an object that holds information about vectors.

Arguments

items

A list of floating-point numbers that make up vectors.

Return value

Returns a vector object.

Halfvec(item)

Creates an object that holds information about half-precision vectors.

Arguments

items

A list of floating-point numbers that form half-precision vectors.

Return value

Returns a halfvec object.

Sparsevec(count, elementcount, items)

Creates an object that holds information about sparse vectors.

Arguments

count

The dimensions of a vector.

elementcount

The number of non-zero items in a vector.

items

A dictionary of index value pairs for each non-zero item.

Return value

Returns a sparsevec object.

Type objects

numeric

This type object describes an object that holds numbers with a very large number of digits. By default, this type object is used to fetch numeric or decimal columns from the cursor. You can also create a numeric object using the Numeric() constructor.

Attributes

digits

A tuple of integers that specifies all the digits of a numeric object. Each element of the tuple contains four digits.

weight

The index of the last digits element that refers to the integer part of a numeric object.

scale

The number of digits in the fractional part of a numeric object.

sign

Specifies whether a numeric object is positive or negative, or has a special value.
The possible values are:
  • 0x0000 – The numeric value is positive.
  • 0x4000 – The numeric value is negative.
  • 0xC000 – The numeric is NaN.
  • 0xD000 – The numeric value is Infinity.
  • 0xF000 – The numeric value is -Infinity.

Examples

num1 = devart.postgresql.Numeric('-12345678.1234')
repr(num1)
'<devart.postgresql.numeric object at 0x...; weight=1, scale=4, sign=16384, digits=(1234, 5678, 1234)>'
The value 12345678.1234 is split into four-digit groups, which are then converted to integers. In this example, there are three digits elements: 1234, 5678, and 1234. The first two digits elements contain the integer part of the value, so the weight is 1. The fractional part of the value consists of four digits, so the scale is 4. Since the value is negative, the sign is 0x4000.
>>> num2 = devart.postgresql.Numeric('NaN')
repr(num2)
'<devart.postgresql.numeric object at 0x...; weight=0, scale=0, sign=49152, digits=()>'
Since the value is NaN, the numeric object contains no data other than the sign attribute, which is 0xC000.

point

This type object describes an object that holds coordinates of a point on a plane. By default, this type object is used to fetch point columns from the cursor. You can also create a point object using the Point() constructor.

Attributes

x

y

The coordinates of the point.

lseg

This type object describes an object that holds information about a line segment. By default, this type object is used to fetch lseg columns from the cursor. You can also create a lseg object using the Lseg() constructor.

Attributes

start

end

The endpoints of the line segment.

line

This type object describes an object that holds information about a line. By default, this type object is used to fetch line columns from the cursor. You can also create a line object using the Line() constructor.

Attributes

a

b

c

The coefficients of the linear equation ax + by + c = 0 that describes the line.

path

This type object describes an object that holds an array of connected line segments. By default, this type object is used to fetch path columns from the cursor. You can also create a path object using the Path() constructor.

Attributes

points

A list of endpoints of all the segments of the path.

polygon

This type object describes an object that holds information about a polygon. By default, this type object is used to fetch polygon columns from the cursor. You can also create a polygon object using the Polygon() constructor.

Attributes

points

A list of coordinates of all the vertexes of the polygon.

box

This type object describes an object that holds information about a rectangle. By default, this type object is used to fetch box columns from the cursor. You can also create a box object using the Box() constructor.

Attributes

upperright

lowerleft

The opposite corners of the rectangle.

circle

This type object describes an object that holds information about a circle. By default, this type object is used to fetch circle columns from the cursor. You can also create a circle object using the Circle() constructor.

Attributes

center

The center point of the circle.

radius

The radius of the circle.

vector

This type object describes an object that holds information about a vector. By default, this type object is used to fetch vector columns from the cursor. You can also create a vector object using the Vector() constructor.

Attributes

items

A list of floating point numbers that make up a vector.

halfvec

This type object describes an object that keeps information about half-precision vectors. By default, this type object is used to fetch halfvec columns from the cursor. You can also create a halfvec object using the Halfvec() constructor.

Attributes

items

A list of floating-point numbers that form half-precision vectors.

sparsevec

This type object describes an object that stores information about sparse vectors. By default, this type object is used to fetch sparsevec columns from the cursor. You can also create a sparsevec object using the Sparsevec() constructor.

Attributes

count

The dimensions of a vector.
© 2022-2025 Devart. All Rights Reserved. Request Support Python Connectors Forum Provide Feedback