Tables

class mindsdb_sdk.tables.Table(db, name)

Bases: mindsdb_sdk.query.Query

delete(**kwargs)

Deletes record from table using filters

>>> table.delete(a=1, b=2)
Parameters

kwargs – filter

filter(**kwargs)

Applies filters on table table.filter(a=1, b=2) adds where condition to table: ‘select * from table1 where a=1 and b=2’

Parameters

kwargs – filter

Returns

Table object

insert(query: Union[pandas.core.frame.DataFrame, mindsdb_sdk.query.Query])

Insert data from query of dataframe :param query: dataframe of :return:

limit(val: int)

Applies limit condition to table query

Parameters

val – limit size

Returns

Table object

track(column)

Apply tracking column to table. (‘LAST’ keyword in mindsdb) First call returns nothing The next calls return new records since previous call (where value of track_column is greater)

Example:

>>> query = con.databases.my_db.tables.sales.filter(type='house').track('created_at')
>>> # first call returns no records
>>> df = query.fetch()
>>> # second call returns rows with created_at is greater since previous fetch
>>> df = query.fetch()
Parameters

column – column to track new data from table.

Returns

Table object

update(values: Union[dict, mindsdb_sdk.query.Query], on: list = None, filters: dict = None)

Update table by condition of from other table.

If ‘values’ is a dict:

it will be an update by condition ‘filters’ is required used command: update table set a=1 where x=1

If ‘values’ is a Query:

it will be an update from select ‘on’ is required used command: update table on a,b from (query)

Parameters
  • values – input for update, can be dict or query

  • on – list of column to map subselect to table [‘a’, ‘b’, …]

  • filters – dict to filter updated rows, {‘column’: ‘value’, …}

class mindsdb_sdk.tables.Tables(database, api)

Bases: mindsdb_sdk.utils.objects_collection.CollectionBase

Wortking with tables: Get table as Query object

>>> table = tables.get('table1')

Filter and limit

>>> table = table.filter(a=1, b='2')
>>> table = table.limit(3)

Get content of table as dataframe. At that moment query will be sent on server and executed

>>> df = table.fetch()

Creating table

From query:

>>> table = tables.create('table2', query)

From other table

>>> table2 = table.create('table2', table)

Uploading file

>>> db = con.databases.files
>>> db.tables.create('filename', dataframe)

` Droping table

>>> db.tables.drop('table2')
create(name: str, query: Union[pandas.core.frame.DataFrame, mindsdb_sdk.query.Query], replace: bool = False) → Union[mindsdb_sdk.tables.Table, mindsdb_sdk.query.Query]

Create new table and return it.

On mindsdb server it executes command: insert into a (select …)

or if replace is True create table a (select …)

‘select …’ is extracted from input Query

Parameters
  • name – name of table

  • query – Query object

  • replace – if true,

Returns

Table object

drop(name: str)

Delete table

Parameters

name – name of table

get(name: str) → mindsdb_sdk.tables.Table

Get table by name

Parameters

name – name of table

Returns

Table object

list() → List[mindsdb_sdk.tables.Table]

Show list of tables in integration

Returns

list of Table objects