I am running a query where I am converting the output to a boolean, as below
jsonb_path_query(AnchorNode, '$.IsIndexStartDeferred')#>> '{}' )::boolean AS ISINDEXSTARTDEFERRED
The output is correctly shown as True or False, if I copy the result in a Notepad or equivalent editor, but on the dBeaver it shows as [] for False and [v] for True
Is there a way to "show" in dBeaver, the values as True or False?
Thank you
Related
My sample input text is 'IG_ASE_APAC'
I need to write a procedure to match the input value and return true or false.
My input text has some conditions :
The input string length is fixed to 3 (separated by _)
The first word remains the same IG
The second word can be anything from this list (ASE, BSE, DSE)
The third word can be (APAC, FADF, GHFE)
my result should satisfy the 4 conditions:
IG_ASE_APAC - true
IG_DSE_APAC - true
IL_ASE_APAC - false
IG_BSE_FADF - true
I'm very new to the stored procedures. I really appreciate any help you can provide.
Since your rules are quite specific you can get what you are after with a single query with a regular expression.
with test(val) as
( values ('IG_ASE_APAC')
, ('IG_DSE_APAC')
, ('IL_ASE_APAC')
, ('IG_BSE_FADF')
)
select val, val ~ '^IG_(ASE|BSE|DSE)_(APAC|FADF|GHFE)$' pattern_ok
from test;
If you really need a stored procedure (well actually function). Apply the regular expression within an SQL function that returns a boolean, then call that function for each string you need to test. (see demo).
create or replace
function is_valid_pattern(string_in text)
returns boolean
language sql
as $$
select string_in ~ '^IG_(ASE|BSE|DSE)_(APAC|FADF|GHFE)$';
$$;
I will leave it to your research for how the regular expression and the function itself work. It is all in the documentation.
I have a table called 'apple' and I wrote the following query:
select name,
count(name),
case when istasty is null then false else istasty end
from apple
group by name, istasty;
This the output:
I am trying to group the name and istasty flag using following condition:
When the corresponding name column has both true or false, then I return false. In the above image, tala has both true and false istasty column. However, I want to return false because it has atleast one false istasty column.
If after grouping all istasty column for a particular name column is true then return true; Similarly, if all istasty column is false, then return false for that particular name column.
I can achieve using the bool_and operator in postgresql by writing the query:
select name, count(name), bool_and(coalesce(istasty = true, false)) from apple group by name;
Is there any way I can modify my first query so that I add filter in having clause to achieve the same result as I got using bool_and operator in second query? Or is there any other possible way?
Please note I am not using bool_and operator. I appreciate your time. Thank you.
An alternative to using the bool_and operator would be regular conditional aggregation:
SELECT
name,
COUNT(*) AS count,
CASE WHEN SUM(CASE WHEN !istasty THEN 1 ELSE 0 END) > 0
THEN FALSE ELSE TRUE END AS result
FROM apple
GROUP BY name;
I am not sure what you have in mind when you suggest using the HAVING clause. By moving the conditional check to the HAVING clause you may exclude/include specific groups in the query matching the condition.
Your logic (return true only if all values are true) equates to getting the min() boolean value:
select
name,
min(istasty::varchar(5))::boolean
from (select name, case when istasty is null then false else istasty end istasty
from apple
group by name, istasty) x
group by name
Note that postgres doesn't support aggregating boolean values, so you have to cast to character then back to boolean to use min().
I want to filter out the output without rows containing null values or blank columns. I am using SQL Server 2012 there is no option named 'Blank' as in SS2005 where I can filter the rows. I also tried following expression but it gives me error or not showing correct output
=IsNothing(Fields!ABC.Value)!= True
=Fields!ABC.Value = ''
Please suggest the solution.
Pull up the tablix or group properties
Switch to "Filters"
Add a new filter
Set the expression to:
=IsNothing(Fields!YourFieldHere.Value)
Set the type to "Boolean" (see screenshot below) otherwise you'll get a "cannot compare data of types boolean and string" error.
Set the value to false
This works for filtering both rows and groups.
We should use the isNothing method in the Expression, change the Text to Boolean
and then Value will be "True"
for example:
Expression
=IsNothing(Fields!TestA.Value)<>True
(Expression type should be Boolean)
Operator
=
Value
=True
Edit the SQL query, so that it will not return NULL values in the column to group on, but let it return a dummy value; for example: ISNULL(columnA, 'dummy')
In the column group definition add a filter: ColumnA <> 'dummy'.
I have a SSRS report that works with boolean parameter. I would like to add a third option to show all the records on the report. Both true and false. The concept is that the dropdown will include three options (All,True,False).
Is there a way to acheive that?
Thanks,
-Y
Set the dataset filter to something like this:
I have 3 available values for #parmTRUEFALSE
False = False
True = True
All Records = (Null)
=IIF(IsNothing(Parameters!parmTRUEFALSE.Value), ObjectFieldName.Value, Parameters!parmTRUEFALSE.Value)
If the user selects All Records... the filter uses ObjectFieldName.Value and returns all records because #parmTRUEFALSE = (Null) / IsNothing
Select Allow multiple values:
Then add the desired values:
Then add a new filter and convert the field value to String:
Then select the IN operator:
I am working on bug in my Database library which use LibPQ internally.I see following behavior which looks strange to me :
For postgreSql Datatype DATE it returns true if its empty in DB
For postgreSql Datatype TIME it return true if its empty in DB
But for VARCHAR,SMALLINT..it return false even they were empty in DB.
PS. I have not check for other data types yet
The empty string and zero (0) are NOT the same thing as NULL. Run a form of this query to see how many NULLs vs empty strings exist for your field:
SELECT COALESCE(<field_name>,'NULL'), COUNT(*)
FROM <table_name>
WHERE <field_name> = ''
OR <field_name> IS NULL
GROUP BY 1
Replace the empty string ('') in this query with zero to check against numeric fields.