Set value of boolean (type = bit(1)) in Mysql Workbench - mysql-workbench

How can I edit the value of a boolean (type = bit(1)) in Mysql Workbench's result grid of a table?
If I set it to 1 or 0 I get the error :
ERROR 1406: 1406: Data too long for column 'enabled' at row 1

Write b'1' for true, and b'0' for false.

To avoid this well-known bug, you can also write 01 for true/1 and 00 for false/0.
E.g.
results in
which is valid MySql syntax.

You can also use true false keywords for value where true = 1 and false = 0.
MySQL Workbench Version: 6.3.4.0
UPDATE
Mysql Server Version: 5.6.27-log

Related

Modify a value returned from Invoke-sqlcmd

I've searched for a number of hours now and am unable to figure out how to do this.
I query an MSSQL database that returns 2 columns, one of these values is empty/null but does represent something in the SQL database(I've tested disabling it).
How would I check through what is returned from my query for the empty value and modify this to something else?
$TestQuery = Invoke-Sqlcmd -Database $DB -Query $qcd -ServerInstance "SomeInstance\Instance1" -Verbose
Result:
Activity Setting
-------- -------
All Operation Enabled
Backup Enabled
Restore Enabled
Prune Enabled
Aux Copy Enabled
Schedule Enabled
Archive Check Enabled
Tape Erase Enabled
Offline content Index Enabled
Online Content Index Enabled
Enabled
You can see the last item returned doesn't have a value but does reflect a setting in the application we use, I just want to modify that value to "Value1" for example.
Any help is greatly appreciated, I did try using hashtables but had no idea what I was doing despite several hours of googling.
Edit:
My Query:
SELECT JM.opName AS 'Activity',
CASE action
WHEN 1 THEN 'Disabled'
WHEN 2 THEN 'Enabled'
END AS 'Setting'
FROM JMJobAction AS J
LEFT JOIN JMJobOperationNames JM on JM.opType = J.opType
WHERE clientId = 1
AND appType = 0
AND J.opType != 8
AND appId = 1
You may do the following in PowerShell:
$TestQuery = Invoke-Sqlcmd -Database $DB -Query $qcd -ServerInstance "SomeInstance\Instance1"
$TestQuery |
Where { [string]::IsNullOrEmpty($_.Activity) } | Foreach-Object {
$_.Activity = 'Value1' # Update all empty or nulls with Value1
}
$TestQuery # Contains updated results
Note that this does not update the actual database. You will need a separate query that writes back to the database.
When a database table contains a NULL, it is interpreted as the System.DBNull data type in PowerShell. [System.DBNull]::Value is not the same as $null. So if you only wanted to query for NULL values, then your query could more appropriately be modified to the following:
$TestQuery | Where Activity -is [DBNUll]
I don't know if I understand your question correctly.
I understand that you want to have a default_value when there is no data in a column.
That can be solved in your SQL Query with case. Here an example
[Edit] Based on your added query
SELECT
CASE
WHEN JM.opName is null OR JM.opName = '' THEN "DefaultActivity"
ELSE JM.opName
END AS Activity,
CASE action
WHEN 1 THEN 'Disabled'
WHEN 2 THEN 'Enabled'
END AS 'Setting'
FROM JMJobAction AS J
LEFT JOIN JMJobOperationNames JM on JM.opType = J.opType
WHERE clientId = 1
AND appType = 0
AND J.opType != 8
AND appId = 1

no viable alternative at input 'is false'

trying to query database in aws athena but got this error:
WHERE
"fo0"."date" > date'2014-08-03'
AND "re0"."rating" IS NOT NULL
AND "fi0"."is_side" is FALSE
GROUP BY "Name"
HAVING COUNT(DISTINCT "re0"."id") > 10
ORDER BY "% More Loves than Dislikes" DESC
;
I am pretty new to athena. Any resolve is helpful.
It looks like you may need to change this line:
AND "fi0"."is_side" is FALSE
to:
AND "fi0"."is_side" = FALSE
Since it sounds like your is_side datatype is a tinyint, try the following:
ND "fi0"."is_side" = 0

PostgreSQL: return message after count = 0

I have maybe easy question, but I'm completely stucked.
I have script
SELECT COALESCE(COUNT(id), 0) as MyFiels from table
It works fine and when I have zero value it shows 0.
But I want that instead of 0, I can see one line = "NO RESULTS" for example.
I tried:
SELECT COALESCE(to_char(COUNT(id), 'NO RESULT')) as MyFiels from table
And PostgreSQL shows error message:
ERROR: "E" is not supported
SQL state: 0A000
Where I'm incorrect? Any ideas?
I see what is the error, you are trying to use coalesce to convert 0 to string, and coalesce convert null to something. You need use a CASE
SELECT CASE WHEN COUNT(*) = 0 THEN 'NO RESULT'
ELSE CAST(COUNT(*) as TEXT)
END as field
FROM Table

DB2 Merge using multiple columns in ON statement

I have a megre statement that does something like the following:
MERGE INTO TABLE_NAME1 tgt
USING (SELECT CONTRACTOR, TRACTOR, COL1, COL2 FROM TABLE_NAME2) src
ON src.CONTRACTOR = tgt.CONTRACTOR AND src.TRACTOR = tgt.TRACTOR
This is because a contractor can have multiple tractors. The table key is not used because it is an identity key only - auto number on insert.
The Merge runs OK when the table is empty, but when running it again it duplicates the rows where the tractor is null. So I tried:
ON ((src.CONTRACTOR = tgt.CONTRACTOR AND src.TRACTOR = tgt.TRACTOR)
OR (src.CONTRACTOR = tgt.CONTRACTOR AND tgt.TRACTOR IS NULL))
But this causes it to hang. Does DB2 have an issue comparing NULL to NULL?
"Does DB2 have an issue comparing NULL to NULL?" No, it does not. However, the result of such a comparison is unknown, in other words, it is neither true nor false:
$ db2 "select * from sysibm.sysdummy1"
IBMREQD
-------
Y
1 record(s) selected.
$ db2 "select * from sysibm.sysdummy1 where null = null"
IBMREQD
-------
0 record(s) selected.
$ db2 "select * from sysibm.sysdummy1 where null != null"
IBMREQD
-------
0 record(s) selected.
Without seeing your complete statement and sample data it's hard to provide a definite answer, but you may want to try instead:
...ON ((src.CONTRACTOR = tgt.CONTRACTOR AND src.TRACTOR = tgt.TRACTOR
AND tgt.TRACTOR IS NOT NULL))

PlayFramework 2 + Ebean - raw Sql Update query - makes no effect on db

I have a play framework 2.0.4 application that wants to modify rows in db.
I need to update 'few' messages in db to status "opened" (read messages)
I did it like below
String sql = " UPDATE message SET opened = true, opened_date = now() "
+" WHERE id_profile_to = :id1 AND id_profile_from = :id2 AND opened IS NOT true";
SqlUpdate update = Ebean.createSqlUpdate(sql);
update.setParameter("id1", myProfileId);
update.setParameter("id2", conversationProfileId);
int modifiedCount = update.execute();
I have modified the postgresql to log all the queries.
modifiedCount is the actual number of modified rows - but the query is in transaction.
After the query is done in the db there is ROLLBACK - so the UPDATE is not made.
I have tried to change db to H2 - with the same result.
This is the query from postgres audit log
2012-12-18 00:21:17 CET : S_1: BEGIN
2012-12-18 00:21:17 CET : <unnamed>: UPDATE message SET opened = true, opened_date = now() WHERE id_profile_to = $1 AND id_profile_from = $2 AND opened IS NOT true
2012-12-18 00:21:17 CET : parameters: $1 = '1', $2 = '2'
2012-12-18 00:21:17 CET : S_2: ROLLBACK
..........
Play Framework documentation and Ebean docs - states that there is no transaction /if not declared or transient if needed per query/.
So... I have made the trick
Ebean.beginTransaction();
int modifiedCount = update.execute();
Ebean.commitTransaction();
Ebean.endTransaction();
Logger.info("update mod = " + modifiedCount);
But this makes no difference - the same behavior ...
Ebean.execute(update);
Again - the same ..
Next step i did - I annontated the method with
#Transactional(type=TxType.NEVER)
and
#Transactional(type=TxType.MANDATORY)
None of them made a difference.
I am so frustrated with Ebean :(
Anybody can help, please ?
BTW.
I set
Ebean.getServer(null).getAdminLogging().setDebugGeneratedSql(true);
Ebean.getServer(null).getAdminLogging().setDebugLazyLoad(true);
Ebean.getServer(null).getAdminLogging().setLogLevel(LogLevel.SQL);
to see in Play console the query - other queries are logged - this update - not
just remove the initial space...Yes..I couldn't believe it either...
change from " UPDATE... to "UPDATE...
And thats all...
i think you have to use raw sql instead of createSqlUpdate statement.