Default values in Column of type variable length array Postgresql - database

My question is how can I set the default values for a certain index in variable length array column. I am trying to set the value of one of the positions to default to string 'false'.
Reason being is I want to be able to have a where clause on a query to filter items where the position value is 'true' (I am setting specific ones to true manually) but without having the rest of my data default to false on that value my query is not fetching any data.
If this is confusing let me know and I will try to clear it up..Thanks in advance

Generally, a column default is for the whole column - for the whole array in your case.
You would have to write a trigger for that. But you may not need any of this. I quote your question:
... but without having the rest of my data default to false on that value
my query is not fetching any data.
You can probably avoid this if you query with:
(arr[5] = 'true') IS NOT TRUE
(which includes all cases there the flag is anything but 'true', even NULL) instead of:
arr[5] &lt&gt 'true'
And if you need this query fast you can support it with a partial index:
CREATE INDEX tbl_special_idx ON tbl (col1) -- potentially more columns
WHERE (arr[5] = 'true') IS NOT TRUE;
The important part is the WHERE clause. You can use columns in place of col1 that might cover the whole query (especially in v9.2) or that have additional conditions in your query ...

Related

Can I replace null values in returned rows in QuestDB?

Some aggregate queries are returning null values, is there a way to handle this?
select time, avg(temp_f) from sensor_data sample by 1h
If some records are missing, can the aggregate be set to something other than null?
If your dataset has gaps of time and is missing entire records for a certain duration, you can use FILL(). You can choose a fill strategy, such as LINEAR for interpolation, PREV for filling with the previous value, or you can specify constants. This will include new rows in the returned response where there were gaps:
SELECT time, avg(temp_f)
FROM sensor_data
SAMPLE BY 1h FILL(50);
If your dataset has records for a certain period, but a sensor was sending null instead of a value, you can use coalesce() to specify how null should be handled. No new rows are returned and a default is set for null values:
SELECT time, coalesce(avg(temp_f), 50)
FROM sensor_data
SAMPLE BY 1h;
For more information, see the FILL keyword documentation and for coalesce(), see the conditional functions documentation pages.

Multi value parameter not working in SSRS report

I have a SSRS report. there is a long SQL query on the main query, in the last SELECT I want to filter the results with WHERE expression, the filter should be with a multi value parameter.
I set the parameter in this way:
Create a new Dataset with a query.
Add a new parameter to the Parameters folder (with name NewParam).
Check the "Allow multiple values" checkbox.
Add the parameter to the "Main Query" and set the value with this expression:
=Join(Parameters!NewParam.Value,",")
At the end of the Main Query I filter the results:
select *
from #FinalStatusTbl
where Test_Number in (#NewParam)
order by Priority
The problem is:
On the report when I choose one value from the list I got expected results, but If I choose multi values the results are empty (not got an error.)
Do you have any idea why?
(When I try this: where Test_Number in ('Test 1', 'Test 2') it works well).
When you create a dataset with a sql query, multi valued parameters work with the in(#ParamName) without any changes.
Replace your =Join(Parameters!NewParam.Value,",") with just =Parameters!NewParam.Value and you should be fine.
That said, the reason you see people using that join expression is because sometimes your query will slow down considerably if your parameter has a lot of potential selections and you data is reasonably large. What is done here is to combine the join expression with a string splitting function in the dataset that converts the resulting Value1,Value2,Value3 string value in a table that can be used in the query via inner join.
This is also a requirement if passing multiple values as a parameter to a stored procedure, as you can't use the in(#ParamName) syntax.
You could try taking the parameter out of the where clause and use the parameter in the filters section of the dataset properties.
This will effectively shift the filtering from the SQL to SSRS.
What you need to do is split your string in the database. What is being passed to your query is 'Test 1, Test 2' as a complete string, NOT 'Test 1' and 'Test 2'. This is why a single value works, and multiple values do not.
Here is a really good link on how to split strings, in preparation for your scenario. The function I most often use is the CTE example, which returns a table of my split strings. Then I change my SQL query to use IN on the returned table.
In your example, you will want to write WHERE Test_Number IN (SELECT Item FROM dbo.ufn_SplitStrings(#NewParam) , where ufn_SplitString is the function you create from the link previously mentioned.
This is what I did and it works well to me. You can try it also.
=sum(if(Fields!Business_Code.Value = "PH"
and (Fields!Vendor_Code.Value = "5563"
and Fields!Vendor_Code.Value = "5564"
and Fields!Vendor_Code.Value = "5565"
and Fields!Vendor_Code.Value = "5551")
, Fields!TDY_Ordered_Value.Value , nothing ))

SSIS Excel error column

I am importing an excel file and grabbing data from it. In a handful of string columns, some rows have the value of #VALUE!. How would I filter these rows out in SSIS? I have tried checking for NULL values, as well as checking to see if that row's column is equal to #VALUE!
([ALT_TYPENAME] == "#VALUE!")
However, the rows pass right through and are not filtered at all. Is it even possible to filter for these? The columns are imported as DT_STR.
Ok, you need to change the order in your conditional split. First you are checking if ISNULL == True, then ISNULL == False.
One of those two conditions will always be true, so the row will be sent down that path, and the third condition ( == "#VALUE!") will never be evaluated.
Try evaluating your last condition first.
You can do this by using a Conditional Split transform in between your Excel source and your destination.
Create an object variable (I name mine Discard) and a Recordset Destination based on that variable. Set your Conditional Split's condition to Column == "#VALUE!" and direct anything that meets that criteria to the Recordset to discard it, while everything else follows the default path to your Destination.
If you need to discard based on multiple columns potentially containing "#VALUE!" just expand the condition to an OR that encompasses all of the columns.
An added benefit of this technique is you can use the Discard Recordset at the end of the job to create a fall out report if you need one.

Dynamically Change Where Clause Condition Based on Parameter Selection (SSRS)

I have built an SSRS report, but am unable to get over one hurdle. It may be simple, I am just unsure of how to solve this.
I have a parameter drop down that allows the user to select one of two options, if they select one option the a portion of the where clause should change, and if the other is chosen it would change again. I will post it below :
If master is chosen :
WHERE myId=1 AND myJournal IS NULL
If Idol is chosen :
WHERE myId=1
So basically just adding a condition and taking a condition based on parameter selection....
This seems very rudimentary, I just can't seem to figure it out.
Thanks for any input
How about
WHERE myId=1 AND (myJournal IS NULL OR #Parameter = 'Idol')
assuming your parameter value get set to Idol of course
The way this works is:
If #Parameter = 'Idol', then the OR clause in the brackets will always be true, regardless of the myJournal value. This reduces the entire WHERE clause to WHERE myId=1 AND true, which is the same as WHERE myId=1.
However if #Parameter = 'master', then the OR clause in the brackets will only be true if myJournal IS NULL as #Parameter = 'Idol' is always false. This means the OR clause can be thought of as equivalent to simply myJournal IS NULL.
This reduces the entire WHERE clause to WHERE myId=1 AND myJournal IS NULL, which is what you are after.
You don't provide any information about the way you want to perform the query.
Do you want to do it with an ajax call?
In this case you should have a selectcombo which will set the needed query string and pass this with an ajax request to the php file that will query the database.
If you want some help we need to have some more information about what you are trying to achieve.

Conditional printing depending of empty or null value in Crystal Reports

Suppose I have an StoredProcedure that returns a unique row corresponding to a table with columns "Name" and "Surname".
I want the report to show:
Name: NameField
Surname: SurnameField
Where the "NameField" and "SurnameField" are the fields returned by the StoredProcedure.
The special requirement, is that if "SurnameField" is empty or null, then I don't want to show the "Surname: SurnameField".
How can I achieve this?
The only thing that I thought is breaking the storedprocedure in two, one for Name and one for Surname, and dividing each line in different subreports and selecting "Delete if empty" (or something like that) for the second... but this is really overkill, I guess there's an easier way.
Should be quite a few ways of achieving this. I'm not quite sure how your report is laid out but you can surpress the field and label or entire section (if it has it's own) using a simple formula; isnull({table.field}) or {table.field} = ''
Or if you have set nulls to be treated as defaults rather than exceptions you can simply do: {table.field} = ''
L
Set the field > 1 (assuming all is greater than 1 already) or <> 0.
That should filter out records with a blank in that area.
You can achieve it by Section Expert:
Supposing the name field name is Surname and the table is NAME and the field storing the value of surname is S_NAME_VALUE. You can put up the filter checking if the value is NULL or BLANK.
if {NAME.SURNAME} in ['SNAME'] and
{NAME.S_NAME_VALUE} =''
then
TRUE
I am assuming there are some codes for Surname filtering i.e SNAME.
If not you can use the one condition and mark it as true.
if {NAME.S_NAME_VALUE} = '' then TRUE

Resources