Can't update other rows in an Informix table when uncommitted insert - informix

Below int_nwn table has 1,0 status records five for each.
Tried to insert 11th row which has status 0 and not going to commit.
nwn#tests$echo "select count(*) from int_nwn where status = 1" | dbaccess mydb
Database selected.
(count(*))
5
1 row(s) retrieved.
Database closed.
nwn#test$echo "select count(*) from int_nwn where status = 0" | dbaccess mydb
Database selected.
(count(*))
5
1 row(s) retrieved.
Database closed.
nwn#test$
nwn#test$now inserting a row with uncommit^C
nwn#test$
nwn#test$echo "select count(*) from int_nwn" | dbaccess mydb
Database selected.
252: Cannot get system information for table.
113: ISAM error: the file is locked.
Error in line 1
Near character position 29
Database closed.
nwn#test$
Now table has a lock and trying update the un-commited row which has seq='965155500’ and return the same error as your screenshot.
nwn#test$
nwn#test$
nwn#test$echo "update int_nwn set ret_info='pending' where seq='965155500'" | dbaccess mydb
Database selected.
245: Could not position within a file via an index.
144: ISAM error: key value locked
Error in line 1
Near character position 59
Database closed.
nwn#test$
nwn#test$
Now trying to update other status 0 records five. And it ended with an error.
nwn#test$
nwn#test$echo "update int_nwn set status=1 where status=0" | dbaccess mydb
Database selected.
244: Could not do a physical-order read to fetch next row.
107: ISAM error: record is locked.
Error in line 1
Near character position 42
Database closed.
nwn#test$
Even though the above update failed and the table has the lock below, the update was successful:
nwn#test$echo "update int_nwn set status=1 where seq in (select seq from int_nwn where status=0)" | dbaccess mydb
Database selected.
5 row(s) updated.
Database closed.
nwn#test$
nwn#test$
nwn#test$
nwn#test$echo "select count(*) from int_nwn" | dbaccess mydb
Database selected.
252: Cannot get system information for table.
113: ISAM error: the file is locked.
Error in line 1
Near character position 29
Database closed.
nwn#test$
It seems that I can’t update the above table rows by selecting them via a "duplicates allowed" column name, and it is successful when selecting the rows going to be updated via a unique column. Can someone explain the theory behind this? What is the reason to fail "update int_nwn set status=1 where status=0" and yet allow "update int_nwn set status=1 where seq in (select seq from int_nwn where status=0)" to succeed. This table has row-level locking mode.
##################################
Please check below more informations
#############schema###################
create table "informix".int_nwn
(
seq serial not null ,
col1 decimal(1),
col2 char(100),
col3 char(1),
col4 char(2),
col5 char(15),
msi char(15),
col6 char(300),
col7 datetime year to second,
col8 datetime year to second,
status char(2),
col9 char(20),
ret_info char(800)
)
fragment by round robin in dbsp1 , dbsp2 , dbsp3 , dbsp4
extent size 1048064 next size 524032 lock mode row;
create index "informix".idx_int_nwn_06_1 on "informix"
.int_nwn (status) using btree in idxdbs;
create index "informix".idx_int_nwn_06_2 on "informix"
.int_nwn (msi) using btree in idxdbs;
create unique index "informix".idx_int_nwn_06_3 on "informix"
.int_nwn (seq) using btree in idxdbs;
#############version###################
nwn#test$echo "SELECT DBINFO('version','full') FROM SysTables WHERE Tabid = 1" | dbaccess mydb
Database selected.
(constant)
IBM Informix Dynamic Server Version 11.70.FC8W1XI
1 row(s) retrieved.
Database closed.
##########OS version ###################
nwn#test$cat /etc/release
Oracle Solaris 11.3 SPARC
Copyright (c) 1983, 2017, Oracle and/or its affiliates. All rights reserved.
Assembled 05 October 2017
###########table/db more information ###########
nwn#test$echo "select nrows, ncols, rowsize from systables where tabname='int_nwn'" | dbaccess mydb
Database selected.
nrows ncols rowsize
10.00000000000 13 1277
1 row(s) retrieved.
Database closed.
nwn#test$echo "SELECT name, is_logging, is_buff_log, is_ansi FROM sysdatabases WHERE name='mydb';" | dbaccess sysmaster
Database selected.
name huw
is_logging 1
is_buff_log 1
is_ansi 0
1 row(s) retrieved.
Database closed.
############# corrected update statement with char values. But behavior is same
nwn#test$echo "update int_nwn set status='1' where status='0'" | dbaccess mydb
Database selected.
245: Could not position within a file via an index.
144: ISAM error: key value locked
Error in line 1
Near character position 47
Database closed.
nwn#test$echo "update int_nwn set status='1' where seq in (select seq from int_nwn where status='0')" | dbaccess mydb
Database selected.
5 row(s) updated.
Database closed.
#########################################################################
this is what second session doing at "nwn#test$now inserting a row with uncommit^C"
SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit
Run the current SQL statements.
----------------------- mydb#testdb ----------- Press CTRL-W for Help --------
begin work;
insert into int_nwn(
seq,
col1,
col2,
col3,
col4,
col5,
msi,
col6,
col7,
col8,
status,
col9,
ret_info)
values(
'965155500',
5.000000,
'XXXXXX',
'0',
'40',
'413012624547422',
'3232423423',
'xxxxx',
'2020-12-02 18:23:48',
'2020-12-02 18:23:53',
'0',
'XXXX',
'Operation Successful');
1 row(s) inserted.

Related

How to add an additional fake null column to select result in Informix?

I need to select an additional column which does not exist in the current table in order to unload the data in the correct format.
Suppose I have two different tables as follows.
**
tab1
----
col1 col2 col3
tab2
---
col1 col2
**
Suppose I need to unload 1000 records from tab2 and need to load them into tab1. But there is a mismatch when considering the number of columns. But I'm ok to enter null values for col3 when loading the data into tab1
So my unload command is as follows
unload to data.unl select col1, col2, null as col3 from tab2;
Then I can load the contents of data.unl into tab1. But my problem is that I get a syntax error when I'm trying to unload the data in that way. Please correct me. Someone can argue that I can use a simple insert command with selecting the data from the tab2. But in my actual use-case it is not possible because data volume is so high and I hope to use the ipload.
Here is my sample error:
nwn#nwnhost$ echo "select CURRENT as col1,null as col2 from sysdual" | dbaccess sysmaster
Database selected.
201: A syntax error has occurred.
Error in line 1
Near character position 29
Database closed.
Cast the NULL to the desired type:
SELECT CURRENT AS col1, NULL::INTEGER AS col2
FROM sysmaster:"informix".sysdual;

Auto-filling empty cells with Google Sheets' query

I have a table with data that I want to run a QUERY from.
In the output tab I need just one column from the data tab, but also I have 3 empty columns in the output tab, that are not in the data tab, that I need to be filled automatically, based on conditions, preferably with the QUERY.
I am using a simple QUERY formula to load the data that I have in the source tab to the output tab.
=QUERY('Source'!$A$1:$X, "SELECT A WHERE F IS NOT NULL", 1)
The issue is that I can not have any other formulas in the output sheet, rather than the QUERY itself, as some issues arise when exporting Google Sheet that contains formulas to .CSV.
Regardless if the above is true or not, these are the rules...
This is the output that I need to have:
+---------+------------+-------------------+-----------------+
| Country | Researched | Status | Reason |
+---------+------------+-------------------+-----------------+
| UK | TRUE | In Progress | |
+---------+------------+-------------------+-----------------+
| US | TRUE | Unable to Proceed | Not a UK member |
+---------+------------+-------------------+-----------------+
Column 1 is what the QUERY extracts from the source.
Columns 2 to 4 are the ones that I need to create with the QUERY.
The value of each cell in those columns depends on column 1, except for column 2 that needs to have the value "TRUE" for each record.
Is it possible to implement multiple conditions in the QUERY itself, that will fill the empty columns in the output tab, based on conditions?
=QUERY({QUERY(Source!$A$1:$X,
"select A, 'TRUE'
where F is not null
label 'TRUE' 'Researched'", 1),
QUERY(ARRAYFORMULA(IFERROR(VLOOKUP(
QUERY(Source!$A$2:$X,
"select A
where F is not null", 0),
{"UK", "In Progress", ""}, {2, 3}, 0),
{"Unable to Proceed", "Not a UK member"})),
"select *
label Col1 'Status', Col2 'Reason'", 0)}, , 0)

Merging two data sets in order to add default values for missing data

I'm trying to merge two datasets in order to insert default rows for missing data. The use case is that I have a list of dates and attendance numbers for training sessions on those dates, but if I have no records at all for a training session then it's missing from the list.
In my sheet at the moment I have a two column set of dates and attendance numbers, and in another sheet I have worked out all the Wednesdays and Fridays (training days) between the start and end dates of all the sessions we have data for.
Is there a way to merge the two datasets together so that the zero attendance for each session is the base set and then I merge in the rows for which I have data? I've tried using some of the query command but if I specify two datasets using {Sheet1!A1:A,Sheet2!B1:B} I get array errors.
The attendance information is currently gathered with a query like this:
=QUERY({Records!A2:B}, "SELECT Col1, COUNT(Col2) WHERE (Col1 IS NOT NULL) GROUP BY Col1 ORDER BY Col1 ASC LABEL Col1 'Session Date', COUNT(Col2) 'Skaters'") where the Records sheets is just date and names.
If I update it to read from two datasets (=QUERY({Records!A2:B, Scratch!B2:B}, "SELECT Col1, COUNT(Col2) WHERE (Col1 IS NOT NULL) GROUP BY Col1 ORDER BY Col1 ASC LABEL Col1 'Session Date', COUNT(Col2) 'Skaters'")then I get a REF error of Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 982. Actual: 999. Seems fair, as it's created misaligned dataset, rather than merging based on the date column.
I'm probably treating the spreadsheet a bit too much like a database, and while I would be more comfortable dropping into the script editor to resolve this I'm trying to learn a few spreadsheet techniques.
Data
Records looks like this:
| 2018-05-04 | Bob |
| 2018-05-04 | Fred |
| 2018-05-12 | Bob |
So no-one took attendance on the 9th, and so the stats are skewed as Bob gets a misleading 100% attendance record.
I do not understand the details of what you are trying to do but since it seems to involve combining one list of just dates and at least two lists of dates and names offer the following example:
The formula is:
=ArrayFormula(query({Sheet1!B1:C20;Sheet2!E1:F20;Sheet3!I1:J20},"select * where Col2 is not NULL order by Col1 "))

How to use QUERY in Google Sheets to return the row with the maximum date?

I am trying to use QUERY to copy the most recent data in a category to another sheet. See example here. The first sheet has the data I want to copy with the category (row 1 and 3) and the date the data was gathered (row 5).
On the second tab, I am trying to copy over only data that has the tag 6.Portions.B in row 1, Summative in row 3, and the most recent date in row 5.
I have successfully used the QUERY command and double transpose to have only 6.Portions.B and Summative data be copied to the second sheet. However, I am unable to get the QUERY command to show only the most recent date. I am trying to use the following:
=transpose(query(transpose(Data!$1:$15), "select Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15 where Col1 starts with """&C$2&""" and Col3 = 'Summative' and Col5 = max(Col5)"))
It is the and Col5 = max(col5) that isn't working (everything else is fine). Is there some way to further filter by only the most recent date? I have tried using the Filter command, but my range size varies unpredictably based on other factors not shown here, and I haven't been able to get that to work without knowing the exact size of the range.
Sort by the date column in descending order and limit the number of returned rows to 1:
select ... where ... order by Col5 desc limit 1
Strictly speaking, "the row with the maximum date?" is not a well-defined concept: multiple rows may have the same date. If this happens, query will pick one of such rows.

sqlite3 one to one join

I have 2 tables:
CREATE TABLE tbA (
columnA TEXT
)
and
CREATE TABLE tbB (
columnB TEXT
)
tbA has these records:
A1
A2
A3
and
tbB has these records:
B1
B2
B3
How can I retrieve records from both tables while they are matched one to one? I mean if I search for A1 which has ROWID of 1 in tbA, it match the record with the same ROWID from tbB which is B1
what I have tried so far:
select * from tbA cross join tbB where columnA = "A1"
but the result is:
1.> A1 B1
2.> A1 B2
I just need first row(equal ROWID in both table) and not the subsequent rows;
If you accept to create a new column, you can easily join row of two table one by one.
CREATE TABLE tbA (id INTEGER PRIMARY KEY AUTOINCREMENT, columnA TEXT);
CREATE TABLE tbB (id INTEGER PRIMARY KEY AUTOINCREMENT, columnB TEXT);
INSERT INTO tbA (columnA) values ("A1");
INSERT INTO tbA (columnA) values ("A2");
INSERT INTO tbA (columnA) values ("A3");
INSERT INTO tbB (columnB) values ("B1");
INSERT INTO tbB (columnB) values ("B2");
INSERT INTO tbB (columnB) values ("B3");
SELECT tbA.columnA, tbB.columnB FROM tbA, tbB WHERE tbA.id=tbB.id;
A1|B1
A2|B2
A3|B3
thanks for help;
found it; without declaring an explicit column as a PRIMARY KEY and using the implicit rowid column:
SELECT * FROM tbA, tbB WHERE tbA.columnA="A1" and tbA.rowid=tbB.rowid

Resources