Preventing newly added column to become last in order - azure-data-explorer

Is it possible to add a new column to an existing Kusto table somewhere in the middle , I don't want it to become last column in the table. Right now when I am issuing .create-merge table command on an existing table and no matter which order I specify for the new column, it always ends up becoming last column in the table.

You are right and it is also written in the docs:
If the motivation to re-order the column is in query scenarios, you can create a function (view) with the same name of the table that re-order the columns as you like, this will allow existing queries to work uninterrupted and the column order to be adjusted.
If the motivation is the ingestion scenario where column order is significant (such as in CSV ingestion or update policy), the new column should be specified at the end, no way around it.

Related

How to Update a Row in Smartsheet using a userdefined (primarykey) column?

Right now im using Smartsheet API 2.0 were i can update only using a RowID (basically a fixed row number) in a Smartsheet. Instead i need to update using a value from a column which i created.
To update a cell you'll need both the row id and the column id. If you want to set a cell values for all cells created after adding a column you'll need to loop over all existing rows and update each of them.
Concerning performance and best practise, while using update rows you can send a batch of rows.

Moving rows in sqlite database

I have a table that is actually a ranking list. I want to give user a chance to rearrange that top the way he wants, ergo, allow him to move the rows in that table. Should I create a separate column that would hold the place, or can it be done using embedded order in table?
The documentation says:
If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined.
(This is true for all SQL databases.)
So you cannot rely on the order that the rows happen to be stored in; you have to use some value in some table column.

Insert into SQLite3 into "middle" of table

I just want to clarify: if you insert a row to a table in sqlite, it appends it to the table, but -- as I learned -- the table is unordered, so there is really not true way to insert a row into the middle of an "ordered table," right?
Is there even a way to make an ordered table without first created a table and then using '...ORDER BY name/id/etc' (i.e. when you insert something it puts itself in the right place)?
SQLite tables are actually stored in rowid order, but this is unlikely to help you because it is unlikely that there is a gap where you want it.
Furthermore, the order in which rows are stored does not matter because there is no guarantee that this is the order in which they are returned.
When you want to SELECT rows in a specific order, you must use ORDER BY.
If your query is too slow, an index on the sorting column might help.

How do I query whether any column in a table contains a certain value without knowing which table I'm querying?

I have a bunch of different tables each of which have an ID column and I want to provide a search feature which will search all columns of all tables and return the ID column of a row that contains a matching string. Since I want to do this for all columns of all tables I cant do a WHERE col1 CONTAINS TEXT_STRING OR col2 .... Any ideas?
Well, if you need to do this, you have a problem with the design. but of course there are many times you have to use what other people put on you!
I would create a view, in the view I would create a union of all possible tables. Later you can just search the view. But you have to build index on that column on all the tables otherwise you will get very bad performance.

How can I insert a new table row into every other row in an existing table?

Ok I have a sqlite db, that has roughly 100 rows. It is kind of a strange thing that I'm trying to do, but I need to insert a new row between each of the existing rows.
I have been trying to use the Insert statement as follows, but haven't had any luck:
insert into t1(column1) values("hello") where id%2 == 0
So I'm basically trying to use the %-operator to tell me if the id is even or odd. For every even id number, I'd like to insert a new row.
What am I missing? What can I do differently? How can I insert a new row into every other row and have the index updated as well?
Thanks
Your question assumes that the rows have some kind of built-in order to them, and that you can insert rows between other rows. That's not true.
It is true that rows have an order on disk, and that the id column is usually assigned in order, but that's an implementation detail. When you perform a query, the database is free to return the rows in any order it chooses, unless you specify what you want with an ORDER BY clause.
Now, I'm assuming what you really want is to insert rows between the existing rows in id order. One way to get what you want would look like this:
UPDATE t1 SET id = id * 2
INSERT INTO t1 (id, column) SELECT id+1, "hello" FROM t1
The UPDATE would double the ids of all the existing rows (so 1,2,3 becomes 2,4,6); then the INSERT would perform a query on t1 and use the result to insert a new set of rows with id values one more than the existing rows (so 2,4,6 becomes 3,5,7).
I haven't tested the above statements, so I don't know if they would work or if they require some extra trickery (like a temporary table) since we are querying and updating the same table in one statement. Also I may have made a syntax error.
Don't consider the rows as pre-ordered in the database. A database will store them as they come in, or according to an index. It's your task to order them on retrieval (i.e. when you query for data) according to your needs.

Resources