Informix: Error -528 Maximum output rowsize (32767) exceeded - informix

i'm developing on a Informix database (v. 12FC9DE) and getting the error -528 (Maximum output rowsize exceeded) when executing following SELECT:
SELECT
genbson(row("typ", "name", "sortName", "longName", "shortName", "status", "dates", "comment", "customer"), 1, 1)::JSON
FROM (
(SELECT
genbson(row("name", "shortName"), 1, 1) as "typ",
'{"de":"Max"}'::JSON::BSON as "name",
'{"de":"Mustermann Max"}'::JSON::BSON as "sortName",
'{"de":"Max Mustermann"}'::JSON::BSON as "longName",
'{"de":"M. Mustermann"}'::JSON::BSON as "shortName",
'A' as "status",
genbson(row("street", "number", "zipCode", "city"), 1, 1) as "address",
genbson(row("phone","fax", "mailaddress", "website"), 1, 1) as "contact",
genbson(row("birthDate", "retireDate"), 1, 1) as "dates",
'red' as "comment",
genbson(row("id"), 1, 1) as "customer"
FROM (
(SELECT
'{"de":"Person"}'::JSON::BSON as "name",
'{"de":"Person"}'::JSON::BSON as "shortName",
'Hauptstraße' as "street",
'1' as "number",
'12345' as "zipCode",
'Musterhausen' as "city",
'012-3456789' as "phone",
'012-34567810' as "fax",
'info#mustermann.de' as "mailaddress",
'www.mustermann.de' as "website",
'1980-02-27'::date as "birthDate",
null::date as "retireDate",
'abdgt-756474-eerrr' as "id"
FROM systables where tabid = 1) as a)
) as b);
With this statement I try to combine several columns to one JSON/BSON-object. The strings in this example that are converted via ::JSON::BSON are in a stored procedure already combined values.
By changing two of these values to normal strings the error does not show up and the SELECT is successful:
SELECT
genbson(row("typ", "name", "sortName", "longName", "shortName", "status", "dates", "comment", "customer"), 1, 1)::JSON
FROM (
(SELECT
genbson(row("name", "shortName"), 1, 1) as "typ",
'{"de":"Max"}'::JSON::BSON as "name",
'{"de":"Mustermann Max"}'::JSON::BSON as "sortName",
'{"de":"Max Mustermann"}' as "longName",
'{"de":"M. Mustermann"}' as "shortName",
'A' as "status",
genbson(row("street", "number", "zipCode", "city"), 1, 1) as "address",
genbson(row("phone","fax", "mailaddress", "website"), 1, 1) as "contact",
genbson(row("birthDate", "retireDate"), 1, 1) as "dates",
'red' as "comment",
genbson(row("id"), 1, 1) as "customer"
FROM (
(SELECT
'{"de":"Person"}'::JSON::BSON as "name",
'{"de":"Person"}'::JSON::BSON as "shortName",
'Hauptstraße' as "street",
'1' as "number",
'12345' as "zipCode",
'Musterhausen' as "city",
'012-3456789' as "phone",
'012-34567810' as "fax",
'info#mustermann.de' as "mailaddress",
'www.mustermann.de' as "website",
'1980-02-27'::date as "birthDate",
null::date as "retireDate",
'abdgt-756474-eerrr' as "id"
FROM systables where tabid = 1) as a)
) as b);
I use DBeaver or DataStudio to execute the SELECT.
In both the error appears.
My question is: why? ;)
Any suggestions on this?
Is it possibly a known bug or am I doing something wrong?
Best regards
S. Kip

To circumvent the 4kB-per-genbson(), which in fact is 4kB-per-BSON, in your query, you can cast each of these genbson(...) calls to an lvarchar(max_expected_length).
SELECT
genbson(row("typ", "name", "sortName", "longName", "shortName", "status", "dates", "comment", "customer"), 1, 1)::JSON::LVARCHAR(400)
FROM (
(SELECT
genbson(row("name", "shortName"), 1, 1)::JSON::LVARCHAR(200) as "typ",
'{"de":"Max"}' as "name",
'{"de":"Mustermann Max"}' as "sortName",
'{"de":"Max Mustermann"}' as "longName",
'{"de":"M. Mustermann"}' as "shortName",
'A' as "status",
genbson(row("street", "number", "zipCode", "city"), 1, 1)::JSON::LVARCHAR(200) as "address",
genbson(row("phone","fax", "mailaddress", "website"), 1, 1)::JSON::LVARCHAR(200) as "contact",
genbson(row("birthDate", "retireDate"), 1, 1)::JSON::LVARCHAR(200) as "dates",
'red' as "comment",
genbson(row("id"), 1, 1)::JSON::LVARCHAR(200) as "customer"
FROM (
(SELECT
'{"de":"Person"}' as "name",
'{"de":"Person"}' as "shortName",
'Hauptstraße' as "street",
'1' as "number",
'12345' as "zipCode",
'Musterhausen' as "city",
'012-3456789' as "phone",
'012-34567810' as "fax",
'info#mustermann.de' as "mailaddress",
'www.mustermann.de' as "website",
'1980-02-27'::date as "birthDate",
null::date as "retireDate",
'abdgt-756474-eerrr' as "id"
FROM systables where tabid = 1) as a)
) as b);
(I've also removed those ::JSON::BSON casts.)

Related

Convert #<ActiveRecord::AssociationRelation to #<ActiveRecord::Relation

Ok, so I'm getting an error breaking my code when the #products array is #<ActiveRecord::AssociationRelation when it's #<ActiveRecord::Relation everything works fine
if params[:collection_id] && params[:collection_id] != ""
#products = Collection.find_by(id: params[:collection_id]).products.not_hidden
else
#products = Product.for_company(#current_company).not_hidden.where(category_id: #category.subtree.visible.ids)
end
puts("===============")
puts #products.inspect
puts("===============")
First case, which causes the error, returns
#<ActiveRecord::AssociationRelation [#<Product id: 29, bar_code: "", deleted: false, price: 3242.0, discounted_price: 52.0, category_id: 15, tags: "", created_at: "2020-12-14 12:29:04", updated_at: "2020-12-17 14:45:26", final_price: 52.0, status: "visible", sku: "", barcode: "", priority: 100, min_quantity: 1, max_quantity: 100, add_shipping_fees: true, weight: 0.0, inventory: {"jklj"=>{"sku"=>"", "barcode"=>"", "quantity"=>"13"}, "ojio9"=>{"sku"=>"", "barcode"=>"", "quantity"=>"555"}}, add_to_inventory: true, is_translated: true, requires_preparing: false, name: "product englishh", description: "">]>
Second case, which works fine, returns
#<ActiveRecord::Relation [#<Product id: 28, bar_code: "", deleted: false, price: 21312.0, discounted_price: 23.0, category_id: 16, tags: "", created_at: "2020-12-10 12:03:37", updated_at: "2020-12-14 13:45:17", final_price: 23.0, status: "visible", sku: "", barcode: "", priority: 100, min_quantity: 1, max_quantity: 234, add_shipping_fees: true, weight: 0.0, inventory: {"ewqeqwr"=>{"sku"=>"", "barcode"=>"", "quantity"=>"0"}}, add_to_inventory: true, is_translated: true, requires_preparing: false, name: "ewqeqwr", description: "<p>qweqw</p>\r\n">,]>
So you can see that the only difference is that the one breaking is AssociationRelation instead of Relation, how can I convert it to Relation?
The error is the following:
PG::InvalidParameterValue: ERROR: cannot call jsonb_each on a non-object
: SELECT DISTINCT "products"."priority" AS alias_0, "products"."id" AS alias_1, "products"."id" FROM "products" LEFT OUTER JOIN "product_translations" ON "product_translations"."product_id" = "products"."id" INNER JOIN "collection_products" ON "products"."id" = "collection_products"."product_id" WHERE "products"."deleted" = $1 AND "collection_products"."collection_id" = $2 AND "products"."status" IN ($3, $4) AND "products"."status" = $5 AND (add_to_inventory =FALSE OR (add_to_inventory =TRUE AND inventory !='{}' )) AND NOT (ARRAY(select distinct (jsonb_each(inventory)).value->>'quantity' as integer)='{0}') ORDER BY "products"."priority" ASC, "products"."id" ASC LIMIT $6 OFFSET $7 excluded from capture: Not configured to send/capture in environment 'development'
The json_b each run happens here
#products = #products.offset(offset)
.limit(#limit)
.where(status: "visible")
.where("add_to_inventory =? OR (add_to_inventory =? AND inventory !=? )", false, true, "{}")
.where.not("ARRAY(select distinct (jsonb_each(inventory)).value->>'quantity' as integer)='{0}'")

how to hide columns of antd data table for small devices(mobile view)?

If the table has five columns i want to display only 2 columns for mobile view
https://ant.design/components/table
you can keep columns in component state and dynamically filter the columns on window resize. Something like this
useEffect(() => {
window.addEventListener("resize", <callback function to update columns>);
// cleanup
return() => window.removeEventListener("resize");
});
Inside render method you need to declare columns with let and change them if window.innerWidth < 480 (I made it less then 500 px to be safe). By changing, I mean filtering from an array of columns only those columns that you want. The best way to filter is by key, because it's unique. This is how the code looks in react:
import React, { PureComponent } from "react";
import { Table } from "antd";
export default class MainPage extends PureComponent {
renderMobileTable = columns => {
return columns.filter(
column => column.key === "name" || column.key === "city"
);
};
render() {
const dataSource = [
{
key: "1",
name: "Mike",
lastName: "Willins",
age: 32,
address: "10 Downing Street",
city: "Chicago"
},
{
key: "2",
name: "John",
lastName: "Billards",
age: 42,
address: "5th Blvd",
city: "New York"
}
];
let columns = [
{
title: "Name",
dataIndex: "name",
key: "name"
},
{
title: "Last Name",
dataIndex: "lastName",
key: "lastName"
},
{
title: "Age",
dataIndex: "age",
key: "age"
},
{
title: "Address",
dataIndex: "address",
key: "address"
},
{
title: "City",
dataIndex: "city",
key: "city"
}
];
const isMobile = window.innerWidth < 500;
if (isMobile) {
columns = this.renderMobileTable(columns);
}
return <Table dataSource={dataSource} columns={columns} />;
}
}
For the source code you may refer to my repository on GitHub.
NOTE: if you are testing mobile view in Chrome Dev Tools, make sure you reload the page after resizing, as we put the logic into render method and the application has to be re-rendered or reloaded.
In antd v4 you can use column prop 'responsive'
const columns = [{
title: 'identification number',
dataIndex: 'ID',
responsive: ['sm'],
}]
https://ant.design/components/table/#Column

How to use rails ActiveRecord to perform a left join of a Model with a subquery

I am using rails 5. When I perform the following straight SQL query in the rails console, I get the following expected result:
2.3.5 :053 > w = ActiveRecord::Base.connection.exec_query("SELECT * FROM students s LEFT JOIN (SELECT student_id, MAX(urgent) AS has_urgent,MAX(created_at) AS last_contact FROM reports GROUP BY student_id) r ON r.student_id = s.id")
(0.5ms) SELECT * FROM students s LEFT JOIN (SELECT student_id, MAX(urgent) AS has_urgent,MAX(created_at) AS last_contact FROM reports GROUP BY student_id) r ON r.student_id = s.id
=> #<ActiveRecord::Result:0x00000000051e1518 #columns=["id", "name", "cwid", "email", "phone", "company", "role", "advisor", "advisor_email", "mentor", "created_at", "updated_at", "student_id", "has_urgent", "last_contact"], #rows=[[1, "Johnny Smith", "71419940", "jsmith#gmail.com", "8435550001", "foxtrot", "mentor", "John I. Moore, Jr.", "john.moore#citadel.edu", "", "2017-11-13 14:58:50.128114", "2017-11-13 14:58:50.128168", nil, nil, nil], [2, "Shelly", "12345678", "shelly#gmail.com", "8435550002", "bravo", "mentee", "Michael P. Verdicchio", "mv#citadel.edu", "Johnny Smith", "2017-11-13 14:58:50.160195", "2017-11-13 14:58:50.160243", "2", "t", "2017-11-13 14:58:50.210105"], [3, "Max", "87654321", "max#gmail.com", "8435550003", "palmetto", "unassigned", "Mei-Qin Chen", "mei.chen#citadel.edu", "", "2017-11-13 14:58:50.179220", "2017-11-13 14:58:50.179258", nil, nil, nil], [4, "George", "87654325", "george#gmail.com", "8435550004", "palmetto", "mentee", "Deepti Joshi", "djoshi#citadel.edu", "Johnny Smith", "2017-11-13 14:58:50.189733", "2017-11-13 14:58:50.189762", "4", "f", "2017-11-03 14:58:50.260914"]], #hash_rows=nil, #column_types={}>
However, this returns an ActiveRecord::Result type, but I really want is to use the Rails ActiveRecord to do the same query but return an ActiveRecord::Relation instead, I thought like so:
2.3.5 :054 > w = Student.joins("LEFT JOIN (SELECT student_id, MAX(urgent) AS has_urgent,MAX(created_at) AS last_contact FROM reports GROUP BY student_id) r ON r.student_id = students.id")
Student Load (0.5ms) SELECT "students".* FROM "students" LEFT JOIN (SELECT student_id, MAX(urgent) AS has_urgent,MAX(created_at) AS last_contact FROM reports GROUP BY student_id) r ON r.student_id = students.id LIMIT ? [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Student id: 1, name: "Johnny Smith", cwid: "71419940", email: "jsmith#gmail.com", phone: "8435550001", company: "foxtrot", role: "mentor", advisor: "John I. Moore, Jr.", advisor_email: "john.moore#citadel.edu", mentor: "", created_at: "2017-11-13 14:58:50", updated_at: "2017-11-13 14:58:50">, #<Student id: 2, name: "Shelly", cwid: "12345678", email: "shelly#gmail.com", phone: "8435550002", company: "bravo", role: "mentee", advisor: "Michael P. Verdicchio", advisor_email: "mv#citadel.edu", mentor: "Johnny Smith", created_at: "2017-11-13 14:58:50", updated_at: "2017-11-13 14:58:50">, #<Student id: 3, name: "Max", cwid: "87654321", email: "max#gmail.com", phone: "8435550003", company: "palmetto", role: "unassigned", advisor: "Mei-Qin Chen", advisor_email: "mei.chen#citadel.edu", mentor: "", created_at: "2017-11-13 14:58:50", updated_at: "2017-11-13 14:58:50">, #<Student id: 4, name: "George", cwid: "87654325", email: "george#gmail.com", phone: "8435550004", company: "palmetto", role: "mentee", advisor: "Deepti Joshi", advisor_email: "djoshi#citadel.edu", mentor: "Johnny Smith", created_at: "2017-11-13 14:58:50", updated_at: "2017-11-13 14:58:50">]>
For this second approach, the Right table columns do not appear in the result, even though the generated SQL looks very similar. I am new to Rails and ActiveRecord, so if someone can help me understand why these two results are different and what I should do to make the second ActiveRecord query work like the straight SQL query I would appreciate it.
If you are using rails 5 then use left_joins or left_outer_joins.
Try this and let me know if it work for you.
Student.left_outer_joins(:reports).select("student.*, MAX(urgent) AS has_urgent,MAX(created_at) AS last_contact").group("student.id").
If you want to go with your first approach then these methods may helpful for you.
result.columns #Get the column names of the result.
result.rows #Get the record values of the result.
result.to_hash #Get an array of hashes representing the result (column => value)
#ActiveRecord::Result also includes Enumerable.

Couchbase N1QL query running, but no data retrieved (wrong query i guess)

I am trying to retrieve data from 2 buckets, no error but nothing shows up (I do have documents I need in these buckets).
1st bucket: a_bucket
here is the document I am interested in (I do have 3 different docs)
author_ID document:
{
"author_ID": 1,
"profil_creation_date": "2017/01/01/01:23:05/+5",
"prefix": "Mr.",
"first_name": "Dylan",
"middle_name_s": "Alfred",
"last_name": "Kerr",
"date_of_birth": "1974/01/02",
"sex": "M",
"marital_status": "Single",
"mobile_phone": "(860) 231-3336",
"address": [
{
"address_1": {
"address_ID": 1,
"home_address": "338 Counts Lane",
"city": "West Hartford",
"province/state": "CT",
"postal_code": "06105"
}
},
{
"address_2": {
"address_ID": 2,
"work_address": "977 Copperhead Rd",
"city": "Newington",
"province/state": "CT",
"postal_code": "06111"
}
}
]
}
2nd bucket: b_bucket
here are the 2 docs I am interested in:
p_output_ID document:
{
"p_output_ID": 1,
"author_ID": 2,
"overall_score": 4.41,
"status": {
"r_status_first": "TRUE",
"r_status_second": "FALSE",
"r_status_third": "YES",
"y_status_second": "TRUE",
"y_status_third": "FALSE",
"g_status_third": "TRUE"
}
}
timing_ID document:
{
"timing_ID": 1,
"p_output_ID": 1,
"author_ID": 1,
"date_and_time": "2017-06-06/23:45:25.25/+5",
"time_in_seconds": 12525,
"incremental_time_in_seconds": "time_in_seconds",
"current_state_and_duration": {
"state": "RED",
"duration_in_seconds": 33333
}
}
my goal is to grab these informations in one query ():
prefix, first_name, middle_name_s, last_name (from author_ID document in a_bucket)
overall_score (from p_output_ID document in b_bucket)
date_and_time, state (from timing_ID document in b_bucket)
Here is my query:
select p2.current_state_and_duration.state, p1.overall_score, p2.date_and_time
from proc_data_bucket p1 USE KEYS "p_output_ID"
JOIN proc_data_bucket p2 ON KEYS "author_ID";
The syntax is OK, but I am getting no data
Please help me with that...
CREATE INDEX ix1 ON b_bucket(timing_ID);
SELECT p1.prefix, p1.first_name, p1.middle_name_s, p1.last_name,
p2.date_and_time,p2.state,
p3.overall_score
FROM b_bucket p2
JOIN a_bucket p1 ON KEYS ("author_" || TO_STRING(p2.author_ID))
JOIN b_bucket p3 ON KEYS ("p_output_" || TO_STRING(p2.p_output_ID))
WHERE p2.timing_ID BETWEEN 10 AND 50;

Rails merge multiple json response

Can anyone help me with this problem?
So, here is the problem, I want to merge this query response:
#energy = Alert.where(["alert_type = ?", "Energy"]).last.as_json
#cost = Alert.where(["alert_type = ?", "Cost"]).last.as_json
Then I merge those object with:
#current_notif = #energy.merge(#cost)
But those just give me #cost object like this:
{
"alert_type": "Cost",
"value": 30000000,
"status": "Cost exceeds limit",
"created_at": "2017-06-03T15:31:21.156+07:00",
"updated_at": "2017-06-03T15:31:21.156+07:00",
"home_id": 2
}
Rather than a merged #energy + #cost like this:
{ {"alert_type": "Energy",
"value": 384455.813978742,
"status": "Energy too high",
"created_at": "2017-05-31T11:31:12.907+07:00",
"updated_at": "2017-05-31T11:31:12.907+07:00",
"home_id": 2 },
{
"alert_type": "Cost",
"value": 30000000,
"status": "Cost exceeds limit",
"created_at": "2017-06-03T15:31:21.156+07:00",
"updated_at": "2017-06-03T15:31:21.156+07:00",
"home_id": 2
}
}
If you want you could "join" both values, and then over that use as_json:
[#energy, #cost].as_json
# [{"alert_type": "Energy", ... }, {"alert_type": "Cost", ... }]
Or if you want you could use the IN expression, in order to deal with ActiveRecord instead having to customize the result this gives you:
Alert.where(alert_type: ['Energy', 'Cost']).as_json
# [{"alert_type": "Energy", ... }, {"alert_type": "Cost", ... }]
This is happening because that's how merge works.
hash = {:name => "Ade", :gender => "Male"}.merge(:name => "Bob")
puts hash # {:name=>"Bob", :gender=>"Male"}
Solution:
results = [ #energy, #cost ]
results.each do |result|
puts result['alert_type'] # Energy, Cost
end

Resources