I have a table with values like: 123, 123A, 123B, 123C, etc.. I am creating a view and need to separate this column into two based on whether or not the value contains a letter.
EX:
Primary (Column 1)
123
Secondary (Column 2)
123A,
123B,
123C,
...
Related
I am a new user of MatlabR2021b and I have a table where the last column (with name loadings) spans multiple sub-columns (all sub-columns were added under the same variable/column and are threated as one column). I wanto to create a For loop that goes through each separate loading column and iterates through them, prior to creating a tbl that I will input into a model. The sub-columns contain numbers with rows corresponding to the number of participants.
Previously, I had a similar analogy where the loop was iterating through the names of different regions of interest, whereas now the loop has to iterate through columns that have numbers in them. First, the numbers in the first sub-column, then in the second, and so on.
I am not sure whether I should split the last column with T1 = splitvars(T1, 'loadings') first or whether I am not indexing into the table correctly or performing the right transformations. I would appreciate any help.
roi.ic = T.loadings;
roinames = roi.ic(:,1);
roinames = [num2str(roinames)];
for iroi = 1:numel(roinames)
f_roiname = roinames{iroi};
tbl = T1;
tbl.(roinames) = T1.loadings(:,roiname);
**tbl.(roinames) = T1.loadings_rsfa(:,roiname)
Unable to use a value of type cell as an index.
Error in tabular/dotParenReference (line 120)
b = b(rowIndices,colIndices)**
I have a table named dept_registration it has a column dept_code so I have to make this field auto-generate but in a specific pattern.
example:- test0001
test0002
test0003
test0004
the "test" should be appended before number automatically after insertion
The column definition could be
dept_code text DEFAULT 'test' || lpad(nextval('myseq')::text, 4, '0')
where myseq is a sequence.
You will get in trouble once the counter reaches 10000...
In a Postgres DB I have a field field defined like this:
CREATE TABLE t (
id SERIAL PRIMARY KEY,
field character varying(255)[] DEFAULT ARRAY[]::character varying[],
);
There I store values like:
ID FIELD
1 {{lower,0},{greater,10}}
2 {{something_else,7},{lower,5}}
1 - How can I select the lower/greater value? I'd like a query response like this:
ID LOWER
1 0
2 5
2 - How can I filter by those lower/greater values?
Thanks!
It's pretty awkward to do but this accomplishes it. I use PG 9.3 so I don't know if there are better ways to do this in later versions.
SELECT id, (SELECT field[ss][2] FROM generate_subscripts(field, 1) ss WHERE field[ss][1] = 'lower') AS lower
FROM t;
Basically, for each record, generate the subscripts to use as indexes into the main array to access the subarrays. For each, look for an array where the first item is 'lower'. If found, return the value of the second item.
I have a parent table and a child table. The parent table only lists ranges of attributes. I'm looking to merge the two to create a proper hierarchy, but I need a way to filter the child table by the parent range first, I believe.
Here is a sample of the parent table:
parent_item start_attribute end_attribute
A 10 120
B 130 130
C 140 200
And the child table:
child_item child_attribute
U 10
V 50
W 60
X 130
Y 140
Z 150
The output table I'd be looking for is such:
parent_item child_item
A U
A V
A W
B X
C Y
C Z
To further confuse things, the attributes are alphanumeric, which eliminates uses a List.Generate() function I believe. I think I'm looking for something similar to the EARLIER() function in DAX, but I'm not sure I'm even looking at this problem the right way. Here is my pseudo code as I'd see it working:
Table.AddColumn(
#"parent_table",
"child_item",
each
Table.SelectRows(
child_table,
each ([child_attribute] <= EARLIER(end_attribute) and [child_attribute]>= EARLIER(start_attribute) )
)
)
This is a simplification as the child table actually contains five attributes and the parent table contains five respective attribute ranges.
I found this blog post, which held the key to referencing the current row environment. The main takeaway is this:
Each is a keyword to create simple functions. Each is an abbreviation for (_) =>, in which the underscore represents (if you are in a table environment, as we are) the current row.
Using a new function C for child_table, we can write
= Table.AddColumn(#"parent_table", "child_table", each
Table.SelectRows(Child, (C) =>
C[child_attribute] >= [start_attribute] and
C[child_attribute] <= [end_attribute]))
or more explicitly as
= Table.AddColumn(#"parent_table", "child_table", (P) =>
Table.SelectRows(Child, (C) =>
C[child_attribute] >= P[start_attribute] and
C[child_attribute] <= P[end_attribute]))
Once you add this column, just expand the child_item column from your new child_table column.
One possible approach is to do a full cross join and then filter out the rows you don't want.
Create a custom column on both tables with a constant value of, say, 1.
Merge the Child table into the Parent table matching on the new column.
Expand out the Child table to get a table like this:
Create a custom column with all your desired logic. For example,
if [child_attribute] >= [start_attribute] and
[child_attribute] <= [end_attribute]
then 1
else 0
Filter out just the 1 values in this new column.
Remove all other columns except for parent_item and child_item.
My column family needs two composite columns, the key data type is BytesType.
Here is the definition of table using CQL:
CREATE TABLE stats (
gid blob,
period int,
tid blob,
sum int,
uniques blob,
PRIMARY KEY(gid, period, tid)
);
What I want to do is to create the column family but with Cassandra CLI. Here is my shot.
The structure of the first composite is:
CompositeType(Int32Type, BytesType, AsciiType)
and it will holds an integer.
The structure of the second composite is:
CompositeType(Int32Type, BytesType)
and will holds BytesType.
create column family stats with comparator = 'CompositeType(Int32Type, BytesType, AsciiType)';
I'm not sure how to define the second composite column in create column family command.
Of course I'm assuming that the table created with CQL will generate two composite columns.
You can only have one comparator on a column family in cassandra. This means you can also only have one type of composite column in column family. The table created by the CQL statement you used would actually use the first composite type comparator that you mention:
CompositeType(Int32Type, BytesType, AsciiType)
That comparator can describe all of your schema because of the 'AsciiType' component at the end of your composite. This component of your column names will contain the literal string 'sum' or 'uniques', and the column value will match the type accordingly.
An example using a json style notation:
<bytes> : { # a row key in your stats column family
(100, <bytes>, "sum") : 100, # one column in your row
(100, <bytes>, "uniques") : <bytes>,
(200, <bytes>, "sum") : 200,
(200, <bytes>, "uniques") : <bytes>
}
<bytes> : { # another row in the cf
...
}