I have an update policy which populates a target table column of dynamic type. The update policy logic for populating the dynamic column is as:-
project target_calculated_column = pack("key1",src_col1,
"key2",src_col2,
"key3",src_col3,
.
.
"keyN",src_colN)
The columns src_col1,src_col2,...,src_colN are fixed number of columns coming from a specific table which is source for the update policy. These columns are of various datatypes, mostly some of them are strings and others are integers. Also the main thing here is that these columns may or may not contain any values for the input rows. What this means is that for integer columns values could be null or in case of string columns it could be blank. Now the issue here is that the update policy function is obviously written before hand and hence it can't know which rows will have nulls or blanks etc. That's something that will only be known when update policy starts running. So when the update policy starts running we end up with the following type of data in the target column target_calculated_column , showing one sample value from target row:-
{
"key1":"sometext",
"key2":30,
"key3":null,
"key5":"hello",
"key6":"",
"key7":112,
"key8":"",
"key9":"",
.
.
"keyN":10
}
This demonstrates the problem. I don't want to keep the key value pairs as part of target_calculated_column which are empty (nulls, blanks etc.). I think what I am asking for is a conditional version of pack() that can ignore key value pairs with empty values, but I don't think such an option is there. Is there way I can postprocess target_calculated_column so that I can eliminate such key value pairs? Basically in case of this example I should be getting the following output:-
{
"key1":"sometext",
"key2":30,
"key5":"hello",
"key7":112,
.
.
"keyN":10
}
pack_all([ignore_null_empty]) function allows you to ignore nulls/empty values. If you want to remove some columns you can use the bag_remove_keys() function. The pack() function itself does not provide this option.
Related
I have a column C of type REAL in table F in SQLite. I want to join this everywhere where in another table the negative value of F exists (along with some other fields).
However -C or 0-C etc.. all return the rounded value of C e.g. when C contains "123,456" then -C returns "-123".
Should I cast this via a string first or is the syntax differently?
Looks like the , in 123,456 is meant to be a decimal separator but SQLite treats the whole thing as a string (i.e. '123,456' rather than 123.456). Keep in mind that SQLite's type system is a little different than SQL's as values have types but columns don't:
[...] In SQLite, the datatype of a value is associated with the value itself, not with its container. [...]
So you can quietly put a string (that looks like a real number in some locales) into a real column and nothing bad happens until later.
You could fix the import process to interpret the decimal separator as desired before the data gets into SQLite or you could use replace to fix them up as needed:
sqlite> select -'123,45';
-123
sqlite> select -replace('123,45', ',', '.');
-123.45
I'm defining my own table-valued-functions in sqlite. I'd like to be able to get a list of these functions, along with the names of their arguments and return columns.
I can get everything except a list of their arguments.
Arguments of table-valued-functions are basically hidden columns in SQLite. This is convenient because they don't show up the results, but my problem is I can't inspect them using pragma table_info.
Is there any way to get a list of hidden columns for a (virtual) table?
PRAGMA table_xinfo("table_name")
table_xinfo = table_info + hidden columns
I need to use cast function with length of column in teradata.
say I have a table with following data ,
id | name
1|dhawal
2|bhaskar
I need to use cast operation something like
select cast(name as CHAR(<length of column>) from table
how can i do that?
thanks
Dhawal
You have to find the length by looking at the table definition - either manually (show table) or by writing dynamic SQL that queries dbc.ColumnsV.
update
You can find the maximum length of the actual data using
select max(length(cast(... as varchar(<large enough value>))) from TABLE
But if this is for FastExport I think casting as varchar(large-enough-value) and postprocessing to remove the 2-byte length info FastExport includes is a better solution (since exporting a CHAR() will results in a fixed-length output file with lots of spaces in it).
You may know this already, but just in case: Teradata usually recommends switching to TPT instead of the legacy fexp.
I am dynamically adding columns to a crystal reports data source as explained here Dynamic_Reports.
Here i need remove columns whenever i am not filling values to depends upon columns. These columns are i need to remove from a crystal reports at run time.
Why i need like this means,I have 20 columns and going fill 1st ,2nd ,19th and 20th columns Only.Rest of them having blank space.blank space[columns] are need to remove.
Include a formula checking null value for the particular column and if null dont insert. These you can check after filling in the database.
EDIT:
example:
If !IsNull({Product.Color}) Or InStr({Product.Color}, " ") != 0 Then
totext({Table.Column})
You can drag the required column for which you suspect it will be blank in to the ( ) of IsNull or InStr
This is a question related to getting Drupal CCK fields (just in case that happens to change anything).
I have several Drupal CCK fields with similar names. They have the same name with a number at the end. that I'd like to pull values from these fields (ten fields total). This is the syntax for accessing the fields values:
$node->cck_field_1[0]['value']
$node->cck_field_2[0]['value']
$node->cck_field_3[0]['value']
…etc.
Since they're all separate fields, but they're numbered, I'd like to just loop through incrementally to write out what I need (there's a lot more to what I'm writing than just accessing these fields' data, but they're the determining factors of the rest), but I can't figure out how to insert a variable into that part of the code.
e.g., (if $i were the incremental number variable), I'd like to be able to write the following string as a variable:
'$node->cck_field_' . $i . '[0]["value"]'
I understand about using the curly brackets to create a variable name from a string, but the part I need the variable in needs to be outside of the string. e.g. this works:
${node}->cck_field_1[0]['value']
but this doesn't:
${node->cck_field_1}[0]['value']
(so I can't write ${'node->cck_field'.$i}[0]['value'] )
So how can write this so that I can use $i in place of the number?
This should work:
$node->{'cck_field_' . $i}[0]['value']