Fetch Issue In Record Field - google-bigquery

My Schema is mongoid STRING NULLABLE
order_vfid STRING NULLABLE
order_storeid STRING NULLABLE
order_filterdate DATETIME NULLABLE
order_sortdate DATETIME NULLABLE
order_time DATETIME NULLABLE
order_shopify_name STRING NULLABLE
order_shopify_id STRING NULLABLE
shipping_address RECORD REPEATED
customer_details RECORD REPEATED
order_payment_status STRING NULLABLE
order_fulfillment_status STRING NULLABLE
order_status STRING NULLABLE
order_currency STRING NULLABLE
order_total_paid FLOAT NULLABLE
is_cod INTEGER NULLABLE
line_items RECORD REPEATED
lineitem_id STRING NULLABLE
vfsku STRING NULLABLE
product_shopifyid STRING NULLABLE
variant_shopifyid STRING NULLABLE
quantity FLOAT NULLABLE
name STRING NULLABLE
catalogname STRING NULLABLE
item_total_sold_price FLOAT NULLABLE
discount FLOAT NULLABLE
confirmation_date STRING NULLABLE
item_vforderstatus STRING NULLABLE
product_status STRING NULLABLE
type STRING NULLABLE
total_shipping2 FLOAT NULLABLE
shipping_perquantity2 FLOAT NULLABLE
vfprodid STRING NULLABLE
Now I am fetching data using query and I got error. Please help me out.
My query is SELECT * FROM testdata.orders where line_items.vfsku = 'VFPQ123_VT1'

Check out how to scan for STRUCT field values that satisfy a condition:
SELECT *
FROM testdata.orders
WHERE EXISTS(SELECT 1 FROM UNNEST(line_items) WHERE vfsku = 'VFPQ123_VT1');

Try this
SELECT *
FROM testdata.orders,UNNEST(line_items)
WHERE vfsku = 'VFPQ123_VT1';

Related

Convert integer to string in Presto

I am trying to convert an integer (e.g. 20211008) to a string format (2021-10-08) to use as a primary key in a separate sub-query.
I have tried the following:
primary_key = cast(PARSE_DATETIME(cast(integer as VARCHAR),'yyyyMMdd') as date)
but receive an error: =' cannot be applied to varchar, date"

Operand data type numeric is invalid for '~' operator

~ operator is not working for BIGINT datatype,
UPDATE Table
SET attrEx= attrEx & (~576460752303423488 )
where attrEx != 0
attrEx Type : BIGINT
Error:
Operand data type numeric is invalid for '~' operator.
You need to cast it to bigint
UPDATE Table
SET attrEx= attrEx & (~CAST(576460752303423488 AS bigint) )
where attrEx != 0
This is documented here
Functions return bigint only if the parameter expression is a bigint data type. SQL Server does not automatically promote other integer data types (tinyint, smallint, and int) to bigint.
...snip...
Integer constants greater than 2,147,483,647 are converted to the decimal data type, not the bigint data type.

Cast real type to boolean

I have next query which should change field type from real to boolean:
ALTER TABLE some_table ALTER COLUMN test_flag TYPE boolean USING test_flag::boolean;
but it fails with error:
ERROR: cannot cast type real to boolean
LINE 1: ...st_flag TYPE boolean USING test_flag::boolean;
Use a different USING clause to convert the data:
ALTER TABLE some_table
ALTER COLUMN test_flag TYPE boolean USING (test_flag <> 0.0);

postgresql changing column type from array to integer throwing casting error

I am changing the postgresql column data type from integer[] to integer, while executing below query,
alter table contact_type alter column is_delete set data type integer USING is_delete::integer
i am getting below error
ERROR: cannot cast type integer[] to integer
LINE 1: ...umn is_delete set data type integer USING is_delete::integer
^
SQL state: 42846
Character: 86
but when tried to change datatype from varchar[] to char, below query works fine
alter table contact_type alter column ct_type set data type varchar
i have referred this link so link but it is not working for converting array to normal data type..
Edit :- it is empty table without any data...
You need to pick the array element that you want to use. You can't convert e.g. 42 integers to a single one.
E.g. if you want to use the first element of the array:
alter table contact_type
alter column is_delete
set data type integer USING is_delete[1];
But a column named is_delete should probably be a boolean rather than an integer.

Conversion failed when converting the nvarchar value '%' to data type int

I have an Object Data Source which pulls information from the database where if we don'd have a value for this particular parameter then we want to get all records. So I have a LIKE statement and I'm using a wildcard to return all entries, but this is giving me the error message
System.Data.SqlClient.SqlException (0x80131904): Conversion failed when converting the nvarchar value '%' to data type int.
The table structure for the relevant column is:
[columnName] VARCHAR(50)
The SQL is something similar to:
SELECT [columns] from [table] where [column] LIKE #param
Then in VB I add the parameter:
Dim sessionParam As New Parameter
sessionParam.Name = "param"
sessionParam.DefaultValue = "%"
sessionParam.Type = TypeCode.String
SqlDataSource1.SelectParameters.Add(sessionParam)
So far I've tried casting the parameter value, casting the column, using dbType for the parameter instead of type, but nothing seems to work and I just get the same error. I suspect the column is reading as an int as this column is a mix of values so some are numbers, some are text, therefore SQL is making the 'educated guess' that that value needs to be an int
Conversion failed when converting the nvarchar value '%' to data type int
Is pretty clear that you have a datatype issue. And the wildcard of '%' is certainly not a integer. You are probably having the issue because the column in where [column] LIKE #param is probably an integer. So even though you identify the parameter as string it is still trying to do an integer to string comparison.
So you are comparing like WHERE Integer LIKE String and that throws a datatype conversion error because SQL will automatically try to convert your string to an integer.
To solve if you want to search for a number as a string which doesn't seem like a good idea you would do something like:
WHERE CAST([column] AS VARCHAR(10)) LIKE #param.
Instead of using LIKE if the parameter is NULL, try this instead.
SELECT [columns] from [table] where #param is null or [column] = #param
If you pass in a NULL parameter everything is returned. If it isn't null, then only where the column matches the parameter will be returned.