Using Lists / Arrays in MySQL when migrating from Postgres? [duplicate] - mysql

This question already has answers here:
Syntax array for mysql [closed]
(1 answer)
Is there any array data type in MySQL like in PostgreSQL?
(4 answers)
Closed 5 months ago.
I am moving from Postgres to Mysql (using Prisma as my connector).
This schema used to work:
model Page {
slug String #id
someValue String
...
tags String[]
}
However, mysql doesn't seem to like String[]
Unable to get DMMF from Prisma Client: Error: Schema parsing error:
Field "tags" in model "Page" can't be a list. The current connector
does not support lists of primitive types.
What am I supposed to do in mysql instead?

Related

'OPENJSON' is not a recognized built-in function name [duplicate]

This question already has answers here:
Apply OPENJSON to a single column
(2 answers)
How to parse JSON column to a table with TSQL
(4 answers)
Closed 7 months ago.
I'm using Microsoft SQL Server 2019 - 15.0.4236.7 (X64)
Compatibility Level is 2019 \ 150
I have a very simple query to transpose some JSON that is stored in a column:
SELECT OPENJSON ([fieldname])
FROM mytable
But I keep recieing the error:
'OPENJSON' is not a recognized built-in function name.
Do I need to enable something?

Convert query with STR_TO_DATE to BigQuery syntax [duplicate]

This question already has answers here:
STRING to DATE in BIGQUERY
(4 answers)
Closed 4 years ago.
I have query that uses the following:
STR_TO_DATE(JSON_EXTRACT_SCALAR(fb.p_dataforanalytics,'$.birthday'), '%m/%d/%Y'),
STR_TO_DATE(JSON_EXTRACT_SCALAR(g.p_dataforanalytics,'$.birthday'), '%Y-%m-%d'),
date_format(p_birthday, '%Y-%m-%d')
This syntax works in MySQL but it doesn't work in BigQuery.
I somehow needs to convert it using PARSE_DATE(?) but I can't find the proper syntax for this.
EDIT:
PARSE_DATE('%m/%d/%Y', JSON_EXTRACT_SCALAR(fb.p_dataforanalytics,'$.birthday') ),
PARSE_DATE('%Y-%m-%d', JSON_EXTRACT_SCALAR(g.p_dataforanalytics,'$.birthday')),
PARSE_DATE('%Y-%m-%d', p_birthday)
Dosent work.
I get:
Invalid result from parsing function
and also
on the p_birthday row:
No matching signature for function PARSE_DATE for argument types:
STRING, INT64. Supported signature: PARSE_DATE(STRING, STRING) at
[15:33]
Easy one, with standard SQL:
#standardSQL
SELECT PARSE_DATE('%m/%d/%Y', '6/22/2017')
2017-06-22
https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#supported-format-elements-for-date
JSON_EXTRACT_SCALAR should work unchanged.

Cannot insert ' into my MySQL database in java [duplicate]

This question already has answers here:
How to escape single quotes in MySQL
(19 answers)
Closed 5 years ago.
I have designed java application & mysql database. Textfield also allow to accept whole characters. MySQL database data collation is set to utf8-default & MySQL server version is 5.7. I can type ' character in textfield. But I cannot execute sql syntax with ' in my query.
ex. Name's is not working, but names is working.
Try using an extra ' character
If the name is O'Brain , use it as O''Brain
For example
Select * from employees where name like 'O''Brain'
Make sure you gave same name to your database column name, where you parsing value from the android app.
or
specify your code so we can get more idea.

reading a json in spark [duplicate]

This question already has answers here:
How to query JSON data column using Spark DataFrames?
(5 answers)
Closed 6 years ago.
I have a table in cassandra where it has a column of type 'text'.
The value it holds is a json type of data.
So in each record this column will be having a value like.
{"a":"1", "b":"5", "c":"3", "d":"12"}
Similarly in next record it will have value something like
{"a":"12", "b":"52", "c":"13", "d":"3",}
So what i can say is this column is having a json value in each record.
My requirement is to retreive the values of "b" and "d" of each record using spark/sparksql.
After you read in the Cassandra table you can perform a User Defined Function (UDF) on the text column, and in that udf you can convert the string to a JSON object and return back the fields you require.

Error inserting data into varchar that contains apostrophe? [duplicate]

This question already has an answer here:
Escaping a single quotation within SQL query
(1 answer)
Closed 7 years ago.
I have ruby script that includes a mysql insert that is working fine until it gets to a row that contains data containing an apostrophe. This row is also being populated using a variable and Im unsure how to escape the character so the insert will work successfully.
Any ideas?
Use the quote method on the connection object:
quote(value, column = nil)
API Documentation Link
Quotes the column value to help prevent SQL injection attacks.
Example:
my_name = ActiveRecord::Base.connection.quote("John O'Neil")
my_address = ActiveRecord::Base.connection.quote("R'lyeh")
query = "INSERT INTO companies (name,address) VALUES (#{my_name}, #{my_address})"
ActiveRecord::Base.connection.execute(query);
Original Post:
See this post: Escaping a single quotation within SQL query