Graph database - Graph Theory

Skip to content
Back to top
View this page
Edit this page

# Graph database

This module implements classes (`GraphDatabase`, `GraphQuery`, `GenericGraphQuery`) for interfacing with the `sqlite` database `graphs.db`.

The `GraphDatabase` class interfaces with the `sqlite` database `graphs.db`. It is an immutable database that inherits from `SQLDatabase` (see `sage.databases.sql_db`).

The database contains all unlabeled graphs with 7 or fewer nodes. This class will also interface with the optional database package containing all unlabeled graphs with 8 or fewer nodes. The database(s) consists of five tables, and has the structure given by the function `graph_db_info()` (For a full description including column data types, create a `GraphDatabase` instance and call the method `get_skeleton()`).

AUTHORS:

- Emily A. Kirkman (2008-09-20): first version of interactive queries, cleaned up code and generalized many elements to sage.databases.sql_db.py

- Emily A. Kirkman (2007-07-23): inherits GenericSQLDatabase, also added classes: GraphQuery and GenericGraphQuery

- Emily A. Kirkman (2007-05-11): initial sqlite version

- Emily A. Kirkman (2007-02-13): initial version (non-sqlite)

REFERENCES:

- Data provided by Jason Grout (Brigham Young University). [Online] Available: http://artsci.drake.edu/grout/graphs/

class sage.graphs.graph_database.GenericGraphQuery(query_string, database=None, param_tuple=None)

  Bases: `SQLQuery`

  A query for a `GraphDatabase`.

  INPUT:

  - `query_string` – string representing the SQL query

  - `database` – (default: `None`) the `GraphDatabase` instance to query (if `None` then a new instance is created)

  - `param_tuple` – tuple of strings (default: `None`); what to replace question marks in `query_string` with (optional, but a good idea)

  Note

  This query class is generally intended for developers and more advanced users. It allows you to execute any query, and so may be considered unsafe.

  EXAMPLES:

  See `GraphDatabase` class docstrings or enter:

  Sage

      sage: G = GraphDatabase()
      sage: G.get_skeleton()
      {...

  Python

      >>> from sage.all import *
      >>> G = GraphDatabase()
      >>> G.get_skeleton()
      {...

  to see the underlying structure of the database. Also see `sage.databases.sql_db.SQLQuery` in `sage.databases.sql_db` for more info and a tutorial.

  A piece of advice about ‘?’ and param_tuple: it is generally considered safer to query with a ‘?’ in place of each value parameter, and using a second argument (a tuple of strings) in a call to the `sqlite` database. Successful use of the `param_tuple` argument is exemplified:

  Sage

      sage: G = GraphDatabase()
      sage: q = 'select graph_id,graph6,num_vertices,num_edges from graph_data where graph_id<=(?) and num_vertices=(?)'
      sage: param = (22,5)
      sage: Q = SQLQuery(G, q, param)
      sage: Q.show()
      graph_id             graph6               num_vertices         num_edges
      --------------------------------------------------------------------------------
      18                   D??                  5                    0
      19                   D?C                  5                    1
      20                   D?K                  5                    2
      21                   D@O                  5                    2
      22                   D?[                  5                    3

  [Python]

      >>> from sage.all import *
      >>> G = GraphDatabase()
      >>> q = 'select graph_id,graph6,num_vertices,num_edges from graph_data where graph_id<=(?) and num_vertices=(?)'
      >>> param = (Integer(22),Integer(5))
      >>> Q = SQLQuery(G, q, param)
      >>> Q.show()
      graph_id             graph6               num_vertices         num_edges
      --------------------------------------------------------------------------------
      18                   D??                  5                    0
      19                   D?C                  5                    1
      20                   D?K                  5                    2
      21                   D@O                  5                    2
      22                   D?[                  5                    3

class sage.graphs.graph_database.GraphDatabase

  Bases: `SQLDatabase`

  Graph Database.

  This class interfaces with the `sqlite` database `graphs.db`. It is an immutable database that inherits from `SQLDatabase` (see `sage.databases.sql_db`). The display functions and get_graphs_list create their own queries, but it is also possible to query the database by constructing either a `SQLQuery`.

  The database contains all unlabeled graphs with 7 or fewer nodes. This class will also interface with the optional database package containing all unlabeled graphs with 8 or fewer nodes. The database consists of five tables. For a full table and column structure, call `graph_db_info()`.

  The tables are associated by the unique primary key `graph_id` (int).

  To query this database, we create a `GraphQuery`. This can be done directly with the `query()` method or by initializing one of:

  - `GenericGraphQuery` – allows direct entry of a query string and tuple of parameters. This is the route for more advanced users that are familiar with SQL

  - `GraphQuery` – a wrapper of SQLQuery, a general database/query wrapper of SQLite for new users

  REFERENCES:

  - Data provided by Jason Grout (Brigham Young University). [Online] Available: http://artsci.drake.edu/grout/graphs/

  EXAMPLES:

  Sage

      sage: G = GraphDatabase()
      sage: G.get_skeleton()
      {'aut_grp': {'aut_grp_size': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'edge_transitive': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_fixed_points': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_orbits': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'vertex_transitive': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'degrees': {'average_degree': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'degree_sequence': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'degrees_sd': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'max_degree': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'min_degree': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'regular': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'graph_data': {'complement_graph6': {'index': True,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False},
        'eulerian': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'graph6': {'index': True,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False},
        'graph_id': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': True},
        'lovasz_number': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'num_cycles': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_edges': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_hamiltonian_cycles': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_vertices': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'perfect': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'planar': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'misc': {'clique_number': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'diameter': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'edge_connectivity': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'girth': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'independence_number': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'induced_subgraphs': {'index': True,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False},
        'min_vertex_cover_size': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_components': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_cut_vertices': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_spanning_trees': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'radius': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'vertex_connectivity': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'spectrum': {'eigenvalues_sd': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'energy': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'max_eigenvalue': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'min_eigenvalue': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'spectrum': {'index': False,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False}}}

  Python

      >>> from sage.all import *
      >>> G = GraphDatabase()
      >>> G.get_skeleton()
      {'aut_grp': {'aut_grp_size': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'edge_transitive': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_fixed_points': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_orbits': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'vertex_transitive': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'degrees': {'average_degree': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'degree_sequence': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'degrees_sd': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'max_degree': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'min_degree': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'regular': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'graph_data': {'complement_graph6': {'index': True,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False},
        'eulerian': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'graph6': {'index': True,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False},
        'graph_id': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': True},
        'lovasz_number': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'num_cycles': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_edges': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_hamiltonian_cycles': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_vertices': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'perfect': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'planar': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'misc': {'clique_number': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'diameter': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'edge_connectivity': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False},
        'girth': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'independence_number': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'induced_subgraphs': {'index': True,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False},
        'min_vertex_cover_size': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_components': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_cut_vertices': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'num_spanning_trees': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'radius': {'index': True,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'vertex_connectivity': {'index': True,
         'primary_key': False,
         'sql': 'BOOLEAN',
         'unique': False}},
       'spectrum': {'eigenvalues_sd': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'energy': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'graph_id': {'index': False,
         'primary_key': False,
         'sql': 'INTEGER',
         'unique': False},
        'max_eigenvalue': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'min_eigenvalue': {'index': True,
         'primary_key': False,
         'sql': 'REAL',
         'unique': False},
        'spectrum': {'index': False,
         'primary_key': False,
         'sql': 'TEXT',
         'unique': False}}}

  interactive_query(display_cols, **kwds)

    Generate an interact shell to query the database.

    Warning

    This is no longer implemented since the switch to Python3.

    This method generates an interact shell that allows the user to manipulate query parameters and see the updated results.

    Todo

    This function could use improvement. Add full options of typical `GraphQuery` (i.e.: have it accept list input); and update options in interact to make it less annoying to put in operators.

    EXAMPLES:

    Sage

        sage: D = GraphDatabase()
        sage: D.interactive_query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=5, max_degree=3)                                    # needs sage.symbolic
        Traceback (most recent call last):
        ...
        NotImplementedError: not available in Jupyter notebook

    Python

        >>> from sage.all import *
        >>> D = GraphDatabase()
        >>> D.interactive_query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=Integer(5), max_degree=Integer(3))                                    # needs sage.symbolic
        Traceback (most recent call last):
        ...
        NotImplementedError: not available in Jupyter notebook

  query(query_dict=None, display_cols=None, **kwds)

    Create a GraphQuery on this database.

    For full class details, type `GraphQuery?` and press `Shift` + `Enter`.

    EXAMPLES:

    Sage

        sage: D = GraphDatabase()
        sage: q = D.query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=['<=', 5])          # needs sage.symbolic
        sage: q.show()                                                              # needs sage.symbolic
        Graph6               Num Vertices         Degree Sequence
        ------------------------------------------------------------
        @                    1                    [0]
        A?                   2                    [0, 0]
        A_                   2                    [1, 1]
        B?                   3                    [0, 0, 0]
        BG                   3                    [0, 1, 1]
        BW                   3                    [1, 1, 2]
        Bw                   3                    [2, 2, 2]
        C?                   4                    [0, 0, 0, 0]
        C@                   4                    [0, 0, 1, 1]
        CB                   4                    [0, 1, 1, 2]
        CF                   4                    [1, 1, 1, 3]
        CJ                   4                    [0, 2, 2, 2]
        CK                   4                    [1, 1, 1, 1]
        CL                   4                    [1, 1, 2, 2]
        CN                   4                    [1, 2, 2, 3]
        C]                   4                    [2, 2, 2, 2]
        C^                   4                    [2, 2, 3, 3]
        D??                  5                    [0, 0, 0, 0, 0]
        D?C                  5                    [0, 0, 0, 1, 1]
        D?K                  5                    [0, 0, 1, 1, 2]
        D?[                  5                    [0, 1, 1, 1, 3]
        D?{                  5                    [1, 1, 1, 1, 4]
        D@K                  5                    [0, 0, 2, 2, 2]
        D@O                  5                    [0, 1, 1, 1, 1]
        D@S                  5                    [0, 1, 1, 2, 2]
        D@[                  5                    [0, 1, 2, 2, 3]
        D@s                  5                    [1, 1, 1, 2, 3]
        D@{                  5                    [1, 1, 2, 2, 4]
        DBW                  5                    [0, 2, 2, 2, 2]
        DB[                  5                    [0, 2, 2, 3, 3]
        DBg                  5                    [1, 1, 2, 2, 2]
        DBk                  5                    [1, 1, 2, 3, 3]
        DIk                  5                    [1, 2, 2, 2, 3]
        DK[                  5                    [1, 2, 2, 2, 3]
        DLo                  5                    [2, 2, 2, 2, 2]
        D_K                  5                    [1, 1, 1, 1, 2]
        D`K                  5                    [1, 1, 2, 2, 2]
        E???                 6                    [0, 0, 0, 0, 0, 0]
        E??G                 6                    [0, 0, 0, 0, 1, 1]
        E??W                 6                    [0, 0, 0, 1, 1, 2]
        E??w                 6                    [0, 0, 1, 1, 1, 3]
        E?@w                 6                    [0, 1, 1, 1, 1, 4]
        E?Bw                 6                    [1, 1, 1, 1, 1, 5]
        E?CW                 6                    [0, 0, 0, 2, 2, 2]
        E?C_                 6                    [0, 0, 1, 1, 1, 1]
        E?Cg                 6                    [0, 0, 1, 1, 2, 2]
        E?Cw                 6                    [0, 0, 1, 2, 2, 3]
        E?Dg                 6                    [0, 1, 1, 1, 2, 3]
        E?Dw                 6                    [0, 1, 1, 2, 2, 4]
        E?Fg                 6                    [1, 1, 1, 1, 2, 4]
        E?Ko                 6                    [0, 0, 2, 2, 2, 2]
        E?Kw                 6                    [0, 0, 2, 2, 3, 3]
        E?LO                 6                    [0, 1, 1, 2, 2, 2]
        E?LW                 6                    [0, 1, 1, 2, 3, 3]
        E?N?                 6                    [1, 1, 1, 1, 2, 2]
        E?NG                 6                    [1, 1, 1, 1, 3, 3]
        E@FG                 6                    [1, 1, 1, 2, 2, 3]
        E@HW                 6                    [0, 1, 2, 2, 2, 3]
        E@N?                 6                    [1, 1, 2, 2, 2, 2]
        E@Ow                 6                    [0, 1, 2, 2, 2, 3]
        E@Q?                 6                    [1, 1, 1, 1, 1, 1]
        E@QW                 6                    [1, 1, 1, 2, 2, 3]
        E@T_                 6                    [0, 2, 2, 2, 2, 2]
        E@YO                 6                    [1, 1, 2, 2, 2, 2]
        EG?W                 6                    [0, 1, 1, 1, 1, 2]
        EGCW                 6                    [0, 1, 1, 2, 2, 2]
        E_?w                 6                    [1, 1, 1, 1, 1, 3]
        E_Cg                 6                    [1, 1, 1, 1, 2, 2]
        E_Cw                 6                    [1, 1, 1, 2, 2, 3]
        E_Ko                 6                    [1, 1, 2, 2, 2, 2]
        F????                7                    [0, 0, 0, 0, 0, 0, 0]
        F???G                7                    [0, 0, 0, 0, 0, 1, 1]
        F???W                7                    [0, 0, 0, 0, 1, 1, 2]
        F???w                7                    [0, 0, 0, 1, 1, 1, 3]
        F??@w                7                    [0, 0, 1, 1, 1, 1, 4]
        F??Bw                7                    [0, 1, 1, 1, 1, 1, 5]
        F??GW                7                    [0, 0, 0, 0, 2, 2, 2]
        F??G_                7                    [0, 0, 0, 1, 1, 1, 1]
        F??Gg                7                    [0, 0, 0, 1, 1, 2, 2]
        F??Gw                7                    [0, 0, 0, 1, 2, 2, 3]
        F??Hg                7                    [0, 0, 1, 1, 1, 2, 3]
        F??Hw                7                    [0, 0, 1, 1, 2, 2, 4]
        F??Jg                7                    [0, 1, 1, 1, 1, 2, 4]
        F??Wo                7                    [0, 0, 0, 2, 2, 2, 2]
        F??Ww                7                    [0, 0, 0, 2, 2, 3, 3]
        F??XO                7                    [0, 0, 1, 1, 2, 2, 2]
        F??XW                7                    [0, 0, 1, 1, 2, 3, 3]
        F??Z?                7                    [0, 1, 1, 1, 1, 2, 2]
        F??ZG                7                    [0, 1, 1, 1, 1, 3, 3]
        F??^?                7                    [1, 1, 1, 1, 1, 2, 3]
        F?CJG                7                    [0, 1, 1, 1, 2, 2, 3]
        F?CPW                7                    [0, 0, 1, 2, 2, 2, 3]
        F?CZ?                7                    [0, 1, 1, 2, 2, 2, 2]
        F?C_w                7                    [0, 0, 1, 2, 2, 2, 3]
        F?Ca?                7                    [0, 1, 1, 1, 1, 1, 1]
        F?CaW                7                    [0, 1, 1, 1, 2, 2, 3]
        F?Ch_                7                    [0, 0, 2, 2, 2, 2, 2]
        F?CqO                7                    [0, 1, 1, 2, 2, 2, 2]
        F?LCG                7                    [1, 1, 1, 1, 2, 2, 2]
        F@??W                7                    [0, 0, 1, 1, 1, 1, 2]
        F@?GW                7                    [0, 0, 1, 1, 2, 2, 2]
        FG??w                7                    [0, 1, 1, 1, 1, 1, 3]
        FG?Gg                7                    [0, 1, 1, 1, 1, 2, 2]
        FG?Gw                7                    [0, 1, 1, 1, 2, 2, 3]
        FG?Wo                7                    [0, 1, 1, 2, 2, 2, 2]
        FK??W                7                    [1, 1, 1, 1, 1, 1, 2]
        FK?GW                7                    [1, 1, 1, 1, 2, 2, 2]
        F_?@w                7                    [1, 1, 1, 1, 1, 1, 4]
        F_?Hg                7                    [1, 1, 1, 1, 1, 2, 3]
        F_?XO                7                    [1, 1, 1, 1, 2, 2, 2]

    Python

        >>> from sage.all import *
        >>> D = GraphDatabase()
        >>> q = D.query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=['<=', Integer(5)])          # needs sage.symbolic
        >>> q.show()                                                              # needs sage.symbolic
        Graph6               Num Vertices         Degree Sequence
        ------------------------------------------------------------
        @                    1                    [0]
        A?                   2                    [0, 0]
        A_                   2                    [1, 1]
        B?                   3                    [0, 0, 0]
        BG                   3                    [0, 1, 1]
        BW                   3                    [1, 1, 2]
        Bw                   3                    [2, 2, 2]
        C?                   4                    [0, 0, 0, 0]
        C@                   4                    [0, 0, 1, 1]
        CB                   4                    [0, 1, 1, 2]
        CF                   4                    [1, 1, 1, 3]
        CJ                   4                    [0, 2, 2, 2]
        CK                   4                    [1, 1, 1, 1]
        CL                   4                    [1, 1, 2, 2]
        CN                   4                    [1, 2, 2, 3]
        C]                   4                    [2, 2, 2, 2]
        C^                   4                    [2, 2, 3, 3]
        D??                  5                    [0, 0, 0, 0, 0]
        D?C                  5                    [0, 0, 0, 1, 1]
        D?K                  5                    [0, 0, 1, 1, 2]
        D?[                  5                    [0, 1, 1, 1, 3]
        D?{                  5                    [1, 1, 1, 1, 4]
        D@K                  5                    [0, 0, 2, 2, 2]
        D@O                  5                    [0, 1, 1, 1, 1]
        D@S                  5                    [0, 1, 1, 2, 2]
        D@[                  5                    [0, 1, 2, 2, 3]
        D@s                  5                    [1, 1, 1, 2, 3]
        D@{                  5                    [1, 1, 2, 2, 4]
        DBW                  5                    [0, 2, 2, 2, 2]
        DB[                  5                    [0, 2, 2, 3, 3]
        DBg                  5                    [1, 1, 2, 2, 2]
        DBk                  5                    [1, 1, 2, 3, 3]
        DIk                  5                    [1, 2, 2, 2, 3]
        DK[                  5                    [1, 2, 2, 2, 3]
        DLo                  5                    [2, 2, 2, 2, 2]
        D_K                  5                    [1, 1, 1, 1, 2]
        D`K                  5                    [1, 1, 2, 2, 2]
        E???                 6                    [0, 0, 0, 0, 0, 0]
        E??G                 6                    [0, 0, 0, 0, 1, 1]
        E??W                 6                    [0, 0, 0, 1, 1, 2]
        E??w                 6                    [0, 0, 1, 1, 1, 3]
        E?@w                 6                    [0, 1, 1, 1, 1, 4]
        E?Bw                 6                    [1, 1, 1, 1, 1, 5]
        E?CW                 6                    [0, 0, 0, 2, 2, 2]
        E?C_                 6                    [0, 0, 1, 1, 1, 1]
        E?Cg                 6                    [0, 0, 1, 1, 2, 2]
        E?Cw                 6                    [0, 0, 1, 2, 2, 3]
        E?Dg                 6                    [0, 1, 1, 1, 2, 3]
        E?Dw                 6                    [0, 1, 1, 2, 2, 4]
        E?Fg                 6                    [1, 1, 1, 1, 2, 4]
        E?Ko                 6                    [0, 0, 2, 2, 2, 2]
        E?Kw                 6                    [0, 0, 2, 2, 3, 3]
        E?LO                 6                    [0, 1, 1, 2, 2, 2]
        E?LW                 6                    [0, 1, 1, 2, 3, 3]
        E?N?                 6                    [1, 1, 1, 1, 2, 2]
        E?NG                 6                    [1, 1, 1, 1, 3, 3]
        E@FG                 6                    [1, 1, 1, 2, 2, 3]
        E@HW                 6                    [0, 1, 2, 2, 2, 3]
        E@N?                 6                    [1, 1, 2, 2, 2, 2]
        E@Ow                 6                    [0, 1, 2, 2, 2, 3]
        E@Q?                 6                    [1, 1, 1, 1, 1, 1]
        E@QW                 6                    [1, 1, 1, 2, 2, 3]
        E@T_                 6                    [0, 2, 2, 2, 2, 2]
        E@YO                 6                    [1, 1, 2, 2, 2, 2]
        EG?W                 6                    [0, 1, 1, 1, 1, 2]
        EGCW                 6                    [0, 1, 1, 2, 2, 2]
        E_?w                 6                    [1, 1, 1, 1, 1, 3]
        E_Cg                 6                    [1, 1, 1, 1, 2, 2]
        E_Cw                 6                    [1, 1, 1, 2, 2, 3]
        E_Ko                 6                    [1, 1, 2, 2, 2, 2]
        F????                7                    [0, 0, 0, 0, 0, 0, 0]
        F???G                7                    [0, 0, 0, 0, 0, 1, 1]
        F???W                7                    [0, 0, 0, 0, 1, 1, 2]
        F???w                7                    [0, 0, 0, 1, 1, 1, 3]
        F??@w                7                    [0, 0, 1, 1, 1, 1, 4]
        F??Bw                7                    [0, 1, 1, 1, 1, 1, 5]
        F??GW                7                    [0, 0, 0, 0, 2, 2, 2]
        F??G_                7                    [0, 0, 0, 1, 1, 1, 1]
        F??Gg                7                    [0, 0, 0, 1, 1, 2, 2]
        F??Gw                7                    [0, 0, 0, 1, 2, 2, 3]
        F??Hg                7                    [0, 0, 1, 1, 1, 2, 3]
        F??Hw                7                    [0, 0, 1, 1, 2, 2, 4]
        F??Jg                7                    [0, 1, 1, 1, 1, 2, 4]
        F??Wo                7                    [0, 0, 0, 2, 2, 2, 2]
        F??Ww                7                    [0, 0, 0, 2, 2, 3, 3]
        F??XO                7                    [0, 0, 1, 1, 2, 2, 2]
        F??XW                7                    [0, 0, 1, 1, 2, 3, 3]
        F??Z?                7                    [0, 1, 1, 1, 1, 2, 2]
        F??ZG                7                    [0, 1, 1, 1, 1, 3, 3]
        F??^?                7                    [1, 1, 1, 1, 1, 2, 3]
        F?CJG                7                    [0, 1, 1, 1, 2, 2, 3]
        F?CPW                7                    [0, 0, 1, 2, 2, 2, 3]
        F?CZ?                7                    [0, 1, 1, 2, 2, 2, 2]
        F?C_w                7                    [0, 0, 1, 2, 2, 2, 3]
        F?Ca?                7                    [0, 1, 1, 1, 1, 1, 1]
        F?CaW                7                    [0, 1, 1, 1, 2, 2, 3]
        F?Ch_                7                    [0, 0, 2, 2, 2, 2, 2]
        F?CqO                7                    [0, 1, 1, 2, 2, 2, 2]
        F?LCG                7                    [1, 1, 1, 1, 2, 2, 2]
        F@??W                7                    [0, 0, 1, 1, 1, 1, 2]
        F@?GW                7                    [0, 0, 1, 1, 2, 2, 2]
        FG??w                7                    [0, 1, 1, 1, 1, 1, 3]
        FG?Gg                7                    [0, 1, 1, 1, 1, 2, 2]
        FG?Gw                7                    [0, 1, 1, 1, 2, 2, 3]
        FG?Wo                7                    [0, 1, 1, 2, 2, 2, 2]
        FK??W                7                    [1, 1, 1, 1, 1, 1, 2]
        FK?GW                7                    [1, 1, 1, 1, 2, 2, 2]
        F_?@w                7                    [1, 1, 1, 1, 1, 1, 4]
        F_?Hg                7                    [1, 1, 1, 1, 1, 2, 3]
        F_?XO                7                    [1, 1, 1, 1, 2, 2, 2]

class sage.graphs.graph_database.GraphQuery(graph_db=None, query_dict=None, display_cols=None, immutable=False, **kwds)

  Bases: `GenericGraphQuery`

  A query for an instance of `GraphDatabase`.

  This class nicely wraps the `sage.databases.sql_db.SQLQuery` class located in `sage.databases.sql_db` to make the query constraints intuitive and with as many pre-definitions as possible. (i.e.: since it has to be a `GraphDatabase`, we already know the table structure and types; and since it is immutable, we can treat these as a guarantee).

  Note

  `sage.databases.sql_db.SQLQuery` functions are available for `GraphQuery`. See `sage.databases.sql_db` for more details.

  INPUT:

  - `graph_db` – `GraphDatabase` (default: `None`); instance to apply the query to (If `None`, then a new instance is created)

  - `query_dict` – dictionary (default: `None`); a dictionary specifying the query itself. Format is: `{'table_name': 'tblname', 'display_cols': ['col1', 'col2'], 'expression': [col, operator, value]}`. If not `None`, `query_dict` will take precedence over all other arguments.

  - `display_cols` – list of strings (default: `None`); a list of column names (strings) to display in the result when running or showing a query

  - `immutable` – boolean (default: `False`); whether to return immutable or mutable graphs

  - `kwds` – the columns of the database are all keywords. For a database table/column structure dictionary, call `graph_db_info()`. Keywords accept both single values and lists of length 2. The list allows the user to specify an expression other than equality. Valid expressions are strings, and for numeric values (i.e. Reals and Integers) are: ‘=’,’’,’’,’=’,’=’. String values also accept ‘regexp’ as an expression argument. The only keyword exception to this format is `induced_subgraphs`, which accepts one of the following options:

    - `['one_of', String, ..., String]` – will search for graphs containing a subgraph isomorphic to any of the `graph6` strings in the list

    - `['all_of', String, ..., String]` – will search for graphs containing a subgraph isomorphic to each of the `graph6` strings in the list

  EXAMPLES:

  Sage

      sage: Q = GraphQuery(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=['<=', 5], min_degree=1)
      sage: Q.number_of()
      35
      sage: Q.show()
      Graph6               Num Vertices         Degree Sequence
      ------------------------------------------------------------
      A_                   2                    [1, 1]
      BW                   3                    [1, 1, 2]
      CF                   4                    [1, 1, 1, 3]
      CK                   4                    [1, 1, 1, 1]
      CL                   4                    [1, 1, 2, 2]
      CN                   4                    [1, 2, 2, 3]
      D?{                  5                    [1, 1, 1, 1, 4]
      D@s                  5                    [1, 1, 1, 2, 3]
      D@{                  5                    [1, 1, 2, 2, 4]
      DBg                  5                    [1, 1, 2, 2, 2]
      DBk                  5                    [1, 1, 2, 3, 3]
      DIk                  5                    [1, 2, 2, 2, 3]
      DK[                  5                    [1, 2, 2, 2, 3]
      D_K                  5                    [1, 1, 1, 1, 2]
      D`K                  5                    [1, 1, 2, 2, 2]
      E?Bw                 6                    [1, 1, 1, 1, 1, 5]
      E?Fg                 6                    [1, 1, 1, 1, 2, 4]
      E?N?                 6                    [1, 1, 1, 1, 2, 2]
      E?NG                 6                    [1, 1, 1, 1, 3, 3]
      E@FG                 6                    [1, 1, 1, 2, 2, 3]
      E@N?                 6                    [1, 1, 2, 2, 2, 2]
      E@Q?                 6                    [1, 1, 1, 1, 1, 1]
      E@QW                 6                    [1, 1, 1, 2, 2, 3]
      E@YO                 6                    [1, 1, 2, 2, 2, 2]
      E_?w                 6                    [1, 1, 1, 1, 1, 3]
      E_Cg                 6                    [1, 1, 1, 1, 2, 2]
      E_Cw                 6                    [1, 1, 1, 2, 2, 3]
      E_Ko                 6                    [1, 1, 2, 2, 2, 2]
      F??^?                7                    [1, 1, 1, 1, 1, 2, 3]
      F?LCG                7                    [1, 1, 1, 1, 2, 2, 2]
      FK??W                7                    [1, 1, 1, 1, 1, 1, 2]
      FK?GW                7                    [1, 1, 1, 1, 2, 2, 2]
      F_?@w                7                    [1, 1, 1, 1, 1, 1, 4]
      F_?Hg                7                    [1, 1, 1, 1, 1, 2, 3]
      F_?XO                7                    [1, 1, 1, 1, 2, 2, 2]

  Python

      >>> from sage.all import *
      >>> Q = GraphQuery(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=['<=', Integer(5)], min_degree=Integer(1))
      >>> Q.number_of()
      35
      >>> Q.show()
      Graph6               Num Vertices         Degree Sequence
      ------------------------------------------------------------
      A_                   2                    [1, 1]
      BW                   3                    [1, 1, 2]
      CF                   4                    [1, 1, 1, 3]
      CK                   4                    [1, 1, 1, 1]
      CL                   4                    [1, 1, 2, 2]
      CN                   4                    [1, 2, 2, 3]
      D?{                  5                    [1, 1, 1, 1, 4]
      D@s                  5                    [1, 1, 1, 2, 3]
      D@{                  5                    [1, 1, 2, 2, 4]
      DBg                  5                    [1, 1, 2, 2, 2]
      DBk                  5                    [1, 1, 2, 3, 3]
      DIk                  5                    [1, 2, 2, 2, 3]
      DK[                  5                    [1, 2, 2, 2, 3]
      D_K                  5                    [1, 1, 1, 1, 2]
      D`K                  5                    [1, 1, 2, 2, 2]
      E?Bw                 6                    [1, 1, 1, 1, 1, 5]
      E?Fg                 6                    [1, 1, 1, 1, 2, 4]
      E?N?                 6                    [1, 1, 1, 1, 2, 2]
      E?NG                 6                    [1, 1, 1, 1, 3, 3]
      E@FG                 6                    [1, 1, 1, 2, 2, 3]
      E@N?                 6                    [1, 1, 2, 2, 2, 2]
      E@Q?                 6                    [1, 1, 1, 1, 1, 1]
      E@QW                 6                    [1, 1, 1, 2, 2, 3]
      E@YO                 6                    [1, 1, 2, 2, 2, 2]
      E_?w                 6                    [1, 1, 1, 1, 1, 3]
      E_Cg                 6                    [1, 1, 1, 1, 2, 2]
      E_Cw                 6                    [1, 1, 1, 2, 2, 3]
      E_Ko                 6                    [1, 1, 2, 2, 2, 2]
      F??^?                7                    [1, 1, 1, 1, 1, 2, 3]
      F?LCG                7                    [1, 1, 1, 1, 2, 2, 2]
      FK??W                7                    [1, 1, 1, 1, 1, 1, 2]
      FK?GW                7                    [1, 1, 1, 1, 2, 2, 2]
      F_?@w                7                    [1, 1, 1, 1, 1, 1, 4]
      F_?Hg                7                    [1, 1, 1, 1, 1, 2, 3]
      F_?XO                7                    [1, 1, 1, 1, 2, 2, 2]

  Check the behavior of parameter `immutable`:

  Sage

      sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=3)
      sage: any(g.is_immutable() for g in Q)
      False
      sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=3, immutable=True)
      sage: all(g.is_immutable() for g in Q)
      True

  [Python]

      >>> from sage.all import *
      >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(3))
      >>> any(g.is_immutable() for g in Q)
      False
      >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(3), immutable=True)
      >>> all(g.is_immutable() for g in Q)
      True

  get_graphs_list(immutable=None)

    Return a list of Sage Graph objects that satisfy the query.

    INPUT:

    - `immutable` – boolean (default: `None`); whether to create mutable/immutable graphs. By default (`immutable=None`), follow the behavior of `self`.

    EXAMPLES:

    Sage

        sage: Q = GraphQuery(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=['<=', 5], min_degree=1)
        sage: L = Q.get_graphs_list()
        sage: L[0]
        Graph on 2 vertices
        sage: len(L)
        35

    Python

        >>> from sage.all import *
        >>> Q = GraphQuery(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=['<=', Integer(5)], min_degree=Integer(1))
        >>> L = Q.get_graphs_list()
        >>> L[Integer(0)]
        Graph on 2 vertices
        >>> len(L)
        35

    Check the behavior of parameter `immutable`:

    Sage

        sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=3)
        sage: any(g.is_immutable() for g in Q.get_graphs_list())
        False
        sage: all(g.is_immutable() for g in Q.get_graphs_list(immutable=True))
        True
        sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=3, immutable=True)
        sage: all(g.is_immutable() for g in Q.get_graphs_list())
        True
        sage: any(g.is_immutable() for g in Q.get_graphs_list(immutable=False))
        False

    [Python]

        >>> from sage.all import *
        >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(3))
        >>> any(g.is_immutable() for g in Q.get_graphs_list())
        False
        >>> all(g.is_immutable() for g in Q.get_graphs_list(immutable=True))
        True
        >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(3), immutable=True)
        >>> all(g.is_immutable() for g in Q.get_graphs_list())
        True
        >>> any(g.is_immutable() for g in Q.get_graphs_list(immutable=False))
        False

  number_of()

    Return the number of graphs in the database that satisfy the query.

    EXAMPLES:

    Sage

        sage: Q = GraphQuery(display_cols=['graph6', 'num_vertices', 'degree_sequence'] ,num_edges=['<=', 5], min_degree=1)
        sage: Q.number_of()
        35

    Python

        >>> from sage.all import *
        >>> Q = GraphQuery(display_cols=['graph6', 'num_vertices', 'degree_sequence'] ,num_edges=['<=', Integer(5)], min_degree=Integer(1))
        >>> Q.number_of()
        35

  query_iterator(immutable=None)

    Return an iterator over the results list of the `GraphQuery`.

    INPUT:

    - `immutable` – boolean (default: `None`); whether to create mutable/immutable graphs. By default (`immutable=None`), follow the behavior of `self`.

    EXAMPLES:

    Sage

        sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=7, diameter=5)
        sage: for g in Q:
        ....:     print(g.graph6_string())
        F?`po
        F?gqg
        F@?]O
        F@OKg
        F@R@o
        FA_pW
        FEOhW
        FGC{o
        FIAHo
        sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=7, diameter=5)
        sage: it = iter(Q)
        sage: while True:
        ....:     try: print(next(it).graph6_string())
        ....:     except StopIteration: break
        F?`po
        F?gqg
        F@?]O
        F@OKg
        F@R@o
        FA_pW
        FEOhW
        FGC{o
        FIAHo

    Python

        >>> from sage.all import *
        >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(7), diameter=Integer(5))
        >>> for g in Q:
        ...     print(g.graph6_string())
        F?`po
        F?gqg
        F@?]O
        F@OKg
        F@R@o
        FA_pW
        FEOhW
        FGC{o
        FIAHo
        >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(7), diameter=Integer(5))
        >>> it = iter(Q)
        >>> while True:
        ...     try: print(next(it).graph6_string())
        ...     except StopIteration: break
        F?`po
        F?gqg
        F@?]O
        F@OKg
        F@R@o
        FA_pW
        FEOhW
        FGC{o
        FIAHo

    Check the behavior of parameter `immutable`:

    Sage

        sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=3)
        sage: any(g.is_immutable() for g in Q.query_iterator())
        False
        sage: all(g.is_immutable() for g in Q.query_iterator(immutable=True))
        True
        sage: Q = GraphQuery(display_cols=['graph6'], num_vertices=3, immutable=True)
        sage: all(g.is_immutable() for g in Q.query_iterator())
        True
        sage: any(g.is_immutable() for g in Q.query_iterator(immutable=False))
        False

    [Python]

        >>> from sage.all import *
        >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(3))
        >>> any(g.is_immutable() for g in Q.query_iterator())
        False
        >>> all(g.is_immutable() for g in Q.query_iterator(immutable=True))
        True
        >>> Q = GraphQuery(display_cols=['graph6'], num_vertices=Integer(3), immutable=True)
        >>> all(g.is_immutable() for g in Q.query_iterator())
        True
        >>> any(g.is_immutable() for g in Q.query_iterator(immutable=False))
        False

  show(max_field_size=20, with_picture=False)

    Display the results of a query in table format.

    INPUT:

    - `max_field_size` – integer (default: 20); width of fields in command prompt version

    - `with_picture` – boolean (default: `False`); whether or not to display results with a picture of the graph (available only in the notebook)

    EXAMPLES:

    Sage

        sage: G = GraphDatabase()
        sage: Q = GraphQuery(G, display_cols=['graph6','num_vertices','aut_grp_size'], num_vertices=4, aut_grp_size=4)
        sage: Q.show()
        Graph6               Num Vertices         Aut Grp Size
        ------------------------------------------------------------
        C@                   4                    4
        C^                   4                    4

    Python

        >>> from sage.all import *
        >>> G = GraphDatabase()
        >>> Q = GraphQuery(G, display_cols=['graph6','num_vertices','aut_grp_size'], num_vertices=Integer(4), aut_grp_size=Integer(4))
        >>> Q.show()
        Graph6               Num Vertices         Aut Grp Size
        ------------------------------------------------------------
        C@                   4                    4
        C^                   4                    4

    Sage

        sage: R = GraphQuery(G, display_cols=['graph6','num_vertices','degree_sequence'], num_vertices=4)
        sage: R.show()
        Graph6               Num Vertices         Degree Sequence
        ------------------------------------------------------------
        C?                   4                    [0, 0, 0, 0]
        C@                   4                    [0, 0, 1, 1]
        CB                   4                    [0, 1, 1, 2]
        CF                   4                    [1, 1, 1, 3]
        CJ                   4                    [0, 2, 2, 2]
        CK                   4                    [1, 1, 1, 1]
        CL                   4                    [1, 1, 2, 2]
        CN                   4                    [1, 2, 2, 3]
        C]                   4                    [2, 2, 2, 2]
        C^                   4                    [2, 2, 3, 3]
        C~                   4                    [3, 3, 3, 3]

    [Python]

        >>> from sage.all import *
        >>> R = GraphQuery(G, display_cols=['graph6','num_vertices','degree_sequence'], num_vertices=Integer(4))
        >>> R.show()
        Graph6               Num Vertices         Degree Sequence
        ------------------------------------------------------------
        C?                   4                    [0, 0, 0, 0]
        C@                   4                    [0, 0, 1, 1]
        CB                   4                    [0, 1, 1, 2]
        CF                   4                    [1, 1, 1, 3]
        CJ                   4                    [0, 2, 2, 2]
        CK                   4                    [1, 1, 1, 1]
        CL                   4                    [1, 1, 2, 2]
        CN                   4                    [1, 2, 2, 3]
        C]                   4                    [2, 2, 2, 2]
        C^                   4                    [2, 2, 3, 3]
        C~                   4                    [3, 3, 3, 3]

    Show the pictures (in notebook mode only):

    Sage

        sage: S = GraphQuery(G, display_cols=['graph6','aut_grp_size'], num_vertices=4)
        sage: S.show(with_picture=True)
        Traceback (most recent call last):
        ...
        NotImplementedError: Cannot display plot on command line.

    Python

        >>> from sage.all import *
        >>> S = GraphQuery(G, display_cols=['graph6','aut_grp_size'], num_vertices=Integer(4))
        >>> S.show(with_picture=True)
        Traceback (most recent call last):
        ...
        NotImplementedError: Cannot display plot on command line.

    Note that pictures can be turned off:

    Sage

        sage: S.show(with_picture=False)
        Graph6               Aut Grp Size
        ----------------------------------------
        C?                   24
        C@                   4
        CB                   2
        CF                   6
        CJ                   6
        CK                   8
        CL                   2
        CN                   2
        C]                   8
        C^                   4
        C~                   24

    [Python]

        >>> from sage.all import *
        >>> S.show(with_picture=False)
        Graph6               Aut Grp Size
        ----------------------------------------
        C?                   24
        C@                   4
        CB                   2
        CF                   6
        CJ                   6
        CK                   8
        CL                   2
        CN                   2
        C]                   8
        C^                   4
        C~                   24

    Show your own query (note that the output is not reformatted for generic queries):

    Sage

        sage: (GenericGraphQuery('select degree_sequence from degrees where max_degree=2 and min_degree >= 1', G)).show()
        degree_sequence
        --------------------
        211
        222
        2211
        2222
        21111
        22211
        22211
        22222
        221111
        221111
        222211
        222211
        222211
        222222
        222222
        2111111
        2221111
        2221111
        2221111
        2222211
        2222211
        2222211
        2222211
        2222222
        2222222

    Python

        >>> from sage.all import *
        >>> (GenericGraphQuery('select degree_sequence from degrees where max_degree=2 and min_degree >= 1', G)).show()
        degree_sequence
        --------------------
        211
        222
        2211
        2222
        21111
        22211
        22211
        22222
        221111
        221111
        222211
        222211
        222211
        222222
        222222
        2111111
        2221111
        2221111
        2221111
        2222211
        2222211
        2222211
        2222211
        2222222
        2222222

sage.graphs.graph_database.data_to_degseq(data, graph6=None)

  Convert a database integer data type to a degree sequence list.

  INPUT:

  - `data` – integer data type (one digit per vertex representing its degree, sorted high to low) to be converted to a degree sequence list

  - `graph6` – string (default: `None`); the `graph6` identifier is required for all graphs with no edges, so that the correct number of zeros is returned.

  EXAMPLES:

  Sage

      sage: from sage.graphs.graph_database import data_to_degseq
      sage: data_to_degseq(3221)
      [1, 2, 2, 3]
      sage: data_to_degseq(0, 'D??')
      [0, 0, 0, 0, 0]

  Python

      >>> from sage.all import *
      >>> from sage.graphs.graph_database import data_to_degseq
      >>> data_to_degseq(Integer(3221))
      [1, 2, 2, 3]
      >>> data_to_degseq(Integer(0), 'D??')
      [0, 0, 0, 0, 0]

sage.graphs.graph_database.degseq_to_data(degree_sequence)

  Convert a degree sequence list to a sorted (max-min) integer data type.

  The input degree sequence list (of Integers) is converted to a sorted (max-min) integer data type, as used for faster access in the underlying database.

  INPUT:

  - `degree_sequence` – list of integers; input degree sequence list

  EXAMPLES:

  Sage

      sage: from sage.graphs.graph_database import degseq_to_data
      sage: degseq_to_data([2,2,3,1])
      3221

  Python

      >>> from sage.all import *
      >>> from sage.graphs.graph_database import degseq_to_data
      >>> degseq_to_data([Integer(2),Integer(2),Integer(3),Integer(1)])
      3221

sage.graphs.graph_database.graph6_to_plot(graph6)

  Return a `Graphics` object from a `graph6` string.

  This method constructs a graph from a `graph6` string and returns a `sage.plot.graphics.Graphics` object with arguments preset for the `sage.plot.graphics.Graphics.show()` method.

  INPUT:

  - `graph6` – a `graph6` string

  EXAMPLES:

  Sage

      sage: from sage.graphs.graph_database import graph6_to_plot
      sage: type(graph6_to_plot('D??'))                                               # needs sage.plot
      <class 'sage.plot.graphics.Graphics'>

  Python

      >>> from sage.all import *
      >>> from sage.graphs.graph_database import graph6_to_plot
      >>> type(graph6_to_plot('D??'))                                               # needs sage.plot
      <class 'sage.plot.graphics.Graphics'>

sage.graphs.graph_database.graph_db_info(tablename=None)

  Return a dictionary of allowed table and column names.

  INPUT:

  - `tablename` – restricts the output to a single table

  EXAMPLES:

  Sage

      sage: sorted(graph_db_info())
      ['aut_grp', 'degrees', 'graph_data', 'misc', 'spectrum']

  Python

      >>> from sage.all import *
      >>> sorted(graph_db_info())
      ['aut_grp', 'degrees', 'graph_data', 'misc', 'spectrum']

  Sage

      sage: graph_db_info(tablename='graph_data')
      ['complement_graph6',
       'eulerian',
       'graph6',
       'lovasz_number',
       'num_cycles',
       'num_edges',
       'num_hamiltonian_cycles',
       'num_vertices',
       'perfect',
       'planar']

  [Python]

      >>> from sage.all import *
      >>> graph_db_info(tablename='graph_data')
      ['complement_graph6',
       'eulerian',
       'graph6',
       'lovasz_number',
       'num_cycles',
       'num_edges',
       'num_hamiltonian_cycles',
       'num_vertices',
       'perfect',
       'planar']

sage.graphs.graph_database.subgraphs_to_query(subgraphs, db)

  Return a GraphQuery object required for the induced_subgraphs parameter.

  This method constructs and returns a `GraphQuery` object respecting the special input required for the `induced_subgraphs` parameter.

  INPUT:

  - `subgraphs` – list of strings; the list should be of one of the following two formats:

    - `['one_of', String, ..., String]` – will search for graphs containing a subgraph isomorphic to any of the `graph6` strings in the list

    - `['all_of', String, ..., String]` – will search for graphs containing a subgraph isomorphic to each of the `graph6` strings in the list

  - `db` – a `GraphDatabase`

  Note

  This is a helper method called by the `GraphQuery` constructor to handle this special format. This method should not be used on its own because it doesn’t set any display columns in the query string, causing a failure to fetch the data when run.

  EXAMPLES:

  Sage

      sage: from sage.graphs.graph_database import subgraphs_to_query
      sage: gd = GraphDatabase()
      sage: q = subgraphs_to_query(['all_of', 'A?', 'B?', 'C?'], gd)
      sage: q.get_query_string()
      'SELECT ,,,,,  FROM misc WHERE ( ( misc.induced_subgraphs regexp ? ) AND (
      misc.induced_subgraphs regexp ? ) ) AND ( misc.induced_subgraphs regexp ? )'

  Python

      >>> from sage.all import *
      >>> from sage.graphs.graph_database import subgraphs_to_query
      >>> gd = GraphDatabase()
      >>> q = subgraphs_to_query(['all_of', 'A?', 'B?', 'C?'], gd)
      >>> q.get_query_string()
      'SELECT ,,,,,  FROM misc WHERE ( ( misc.induced_subgraphs regexp ? ) AND (
      misc.induced_subgraphs regexp ? ) ) AND ( misc.induced_subgraphs regexp ? )'