6. Using PGQL results

Retrieving results after executing a PGQL query can be done using the following methods of the PgqlResultSet class.

Please note that this functionality is different from the one included in OPG4Py package. For more details look into the PGQL documentation.

class pypgx.api.PgqlResultSet(graph, java_pgql_result_set)

Result set of a pattern matching query.

Note: retrieving results from the server is not thread-safe.

absolute(row)

Move the cursor to the given row number in this ResultSet object.

If the row number is positive, the cursor moves to the given row number with respect to the beginning of the result set. The first row is 1, so absolute(1) moves the cursor to the first row.

If the row number is negative, the cursor moves to the given row number with respect to the end of the result set. So absolute(-1) moves the cursor to the last row.

Parameters

row – Row to move to

Returns

True if the cursor is moved to a position in the ResultSet object;

False if the cursor is moved before the first or after the last row

after_last()

Place the cursor after the last row

before_first()

Set the cursor before the first row

close()

Free resources on the server taken up by this frame.

destroy()

Free resources on the server taken up by this frame.

first()

Move the cursor to the first row in the result set

Returns

True if the cursor points to a valid row; False if the result set does not

have any results

get(element)

Get the value of the designated element by element index or name

Parameters

element – Integer or string representing index or name

Returns

Content of cell

get_boolean(element)

Get the value of the designated element by element index or name as a Boolean

Parameters

element – Integer or String representing index or name

Returns

Boolean

get_date(element)

Get the value of the designated element by element index or name as a datetime Date

Parameters

element – Integer or String representing index or name

Returns

datetime.date

get_double(element)

Get the value of the designated element by element index or name as a Float

This method is for precision, as a Java floats and doubles have different precisions

Parameters

element – Integer or String representing index or name

Returns

Float

get_edge(element)

Get the value of the designated element by element index or name as a PgxEdge

Parameters

element – Integer or String representing index or name

Returns

PgxEdge

get_float(element)

Get the value of the designated element by element index or name as a Float

Parameters

element – Integer or String representing index or name

Returns

Float

get_integer(element)

Get the value of the designated element by element index or name as an Integer

Parameters

element – Integer or String representing index or name

Returns

Integer

get_legacy_datetime(element)

Get the value of the designated element by element index or name as a Datetime. Works with most time and date type cells. If the date is not specified, default is set to to Jan 1 1970.

Parameters

element – Integer or String representing index or name

Returns

datetime.datetime

get_list(element)

Get the value of the designated element by element index or name as a List

Parameters

element – Integer or String representing index or name

Returns

List

get_long(element)

Get the value of the designated element by element index or name as a Long

Parameters

element – Integer or String representing index or name

Returns

Long

get_point2d(element)

Get the value of the designated element by element index or name as a 2D tuple

Parameters

element – Integer or String representing index or name

Returns

(X, Y)

get_row(row)

Get row from result_set. This method may change result_set cursor.

Parameters

row – Row index

get_slice(start, stop, step=1)

Get slice from result_set. This method may change result_set cursor.

Parameters
  • start – Start index

  • stop – Stop index

  • step – Step size

get_string(element)

Get the value of the designated element by element index or name as a String

Parameters

element – Integer or String representing index or name

Returns

String

get_time(element)

Get the value of the designated element by element index or name as a datetime Time

Parameters

element – Integer or String representing index or name

Returns

datetime.time

get_time_with_timezone(element)

Get the value of the designated element by element index or name as a datetime Time that includes timezone

Parameters

element – Integer or String representing index or name

Returns

datetime.time

get_timestamp(element)

Get the value of the designated element by element index or name as a Datetime

Parameters

element – Integer or String representing index or name

Returns

datetime.datetime

get_timestamp_with_timezone(element)

Get the value of the designated element by element index or name as a Datetime

Parameters

element – Integer or String representing index or name

Returns

datetime.datetime

get_vertex(element)

Get the value of the designated element by element index or name as a PgxVertex

Parameters

element – Integer or String representing index or name

Returns

PgxVertex

get_vertex_labels(element)

Get the value of the designated element by element index or name a list of labels

Parameters

element – Integer or String representing index or name

Returns

list

last()

Move the cursor to the first row in the result set

Returns

True if the cursor points to a valid row; False if the result set does not

have any results

next()

Move the cursor forward one row from its current position

Returns

True if the cursor points to a valid row; False if the new cursor is positioned

after the last row

previous()

Move the cursor to the previous row from its current position

Returns

True if the cursor points to a valid row; False if the new cursor is positioned

before the first row

print(file=None, num_results=1000, start=0)

Print the result set.

Parameters
  • file – File to which results are printed (default is sys.stdout)

  • num_results – Number of results to be printed

  • start – Index of the first result to be printed

relative(rows)

Move the cursor a relative number of row with respect to the current position. A negative number will move the cursor backwards.

Note: Calling relative(1) is equal to next() and relative(-1) is equal to previous. Calling relative(0) is possible when the cursor is positioned at a row, not when it is positioned before the first or after the last row. However, relative(0) will not update the position of the cursor.

Parameters

rows – Relative number of rows to move from current position

Returns

True if the cursor is moved to a position in the ResultSet object; False if

the cursor is moved before the first or after the last row

to_frame()

Copy the content of this result set into a new PgxFrames

Returns

a new PgxFrame containing the content of the result set

to_pandas()

Convert to pandas DataFrame.

This method may change result_set cursor.

This method requires pandas.

Returns

PgqlResultSet as a Pandas Dataframe