I had this error and I don't know how to fix it
Cannot resolve the collation conflict between "Arabic_CI_AS" and
"SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
note: I already change the collation from the database option --> Collation
I change it from "Arabic_CI_AS" to "SQL_Latin1_General_CP1_CI_AS"
and I am still getting the same error !!
Any suggestion to solve this ?
The database collation applies only when you create NEW objects without specifying the collation.
When you change it from "Arabic_CI_AS" to "SQL_Latin1_General_CP1_CI_AS", all the textual columns in the database are still collated Arabic_CI_AS. You can check this using
select object_name(object_id), name, collation_name
from sys.columns
where collation_name like '%Arabic%'
A patch to this problem is to put COLLATE DATABASE_DEFAULT against the comparison, e.g.
SELECT *
FROM TBL1
INNER JOIN TBL2 on X = Y COLLATE DATABASE_DEFAULT
or
SELECT *
FROM TBL1
WHERE X = Y COLLATE DATABASE_DEFAULT
etc
There is a script on this site that attempts to change the collation across an entire database, but
I have not personally tried it
Make sure you have a good backup of your database before trying it
It doesn't look like it will handle complex databases with indexed views, foreign key/default constraints etc
Related
I have created a database but now i wanted to make a column case sensitive for search purposes.
ALTER TABLE hospital_details ALTER COLUMN list COLLATE Latin1_General_CS_AS;
this is the error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COLLATE Latin1_General_CS_AS' at line 1
Review MariaDB's syntax of ALTER TABLE here: https://mariadb.com/kb/en/alter-table/
You can use ALTER TABLE ... ALTER COLUMN only to set a default or drop a default from a column.
If you want to change the column's collation, it's ALTER TABLE ... MODIFY COLUMN but you will have to specify the whole column definition including type, default, and collation.
Also be sure that the version of MariaDB you use supports the collation you named. Use SHOW COLLATION to view the collations available. Read https://mariadb.com/kb/en/show-collation/ for details.
I don't think MySQL or MariaDB support a collation named Latin1_General_CS_AS. What reference did you get that collation name from?
MariaDB does support a collation Latin1_General_CS.
With the release of dplyr 0.7.0, it is now supposedly easy to connect to Oracle using the odbc package. However, I am running into a problem accessing tables not inside the default schema (for me it is my username). For example, suppose there is the table TEST_TABLE in schema TEST_SCHEMA. Then, example SQL syntax to get data would be: select * from TEST_SCHEMA.TEST_TABLE'.
To do the same in `dplyr, I am trying the following:
# make database connection using odbc: [here's a guide][1]
oracle_con <- DBI::dbConnect(odbc::odbc(), "DB")
# attempt to get table data
tbl(oracle_con, 'TEST_SCHEMA.TEST_TABLE')
Now, this leads to an error message:
Error: <SQL> 'SELECT *
FROM ("TEST_SCHEMA.TEST_TABLE") "zzz12"
WHERE (0 = 1)'
nanodbc/nanodbc.cpp:1587: 42S02: [Oracle][ODBC][Ora]ORA-00942: table or view does not exist
I think the problem here is the double quotation marks, as:
DBI::dbGetQuery(oracle_con, "select * from (TEST_SCHEMA.TEST_TABLE) where rownum < 100;")
works fine.
I struggled with this for a while until I found the solution at the bottom of the introduction to dbplyr. The correct syntax to specify the schema and table combo is:
tbl(oracle_con, in_schema('TEST_SCHEMA', 'TEST_TABLE'))
As an aside, I think the issue with quotation marks is lodged here: https://github.com/tidyverse/dplyr/issues/3080
There are also the following alternate work-arounds that may be suitable depending on what you wish to do. Since the connection used DBI, one can alter the schema via:
DBI::dbSendQuery(oracle_con, "alter session set current_schema = TEST_SCHEMA")
after which tbl(oracle_con, 'TEST_TABLE') will work.
Or, if you have create view privileges, you can create a "shortcut" in your default schema to any table you are interested in:
DBI::dbSendQuery(oracle_con, "CREATE VIEW TEST_TABLE AS SELECT *
FROM TEST_SCHEMA.TEST_TABLE")
Note that the latter may be more suitable for applications where you wish to copy local data to the database for a join, but do not have write access to the table's original schema.
My R workflow now involves dealing with a lot of queries (RPostgreSQL library). I really want to make code easy to maintain and manage in the future.
I started loading large queries from separate .SQL files (this helped) and it worked great.
Then I started using interpolated values (that helped) which means that I can write
SELECT * FROM table WHERE value = ?my_value;
and (after loading it into R) interpolate it using sqlInterpolate(ANSI(), query, value = "stackoverflow").
What happens now is I want to use something like this
SELECT count(*) FROM ?my_table;
but how can I make it work? sqlInterpolate() only interpolates safely by default. Is there a workaround?
Thanks
In ?DBI::SQL, you can read:
By default, any user supplied input to a query should be escaped using
either dbQuoteIdentifier() or dbQuoteString() depending on whether it
refers to a table or variable name, or is a literal string.
Also, on this page:
You may also need dbQuoteIdentifier() if you are creating tables or
relying on user input to choose which column to filter on.
So you can use:
sqlInterpolate(ANSI(),
"SELECT count(*) FROM ?my_table",
my_table = dbQuoteIdentifier(ANSI(), "table_name"))
# <SQL> SELECT count(*) FROM "table_name"
sqlInterpolate() is for substituting values only, not other components like table names. You could use other templating frameworks such as brew or whisker.
I found in the peewee documentation how to create custom collations, but I wasn't able to find how to use the built-in sqlite collating sequences.
Ho do I create the following query in peewee (it is the last one in the above mentioned sqlite documentation page)?
SELECT x FROM t1 ORDER BY c COLLATE NOCASE, x;
And how do I specify the collation for an index?
CREATE INDEX i1 ON t1(f1 COLLATE NOCASE);
EDIT
The answer from coleifer addresses the question about the query.
For the index creation I am using the following trick, which works well when you create the indexes only once at startup (like in my app).
The case insensitive unique index on two columns on the table LockedFiles prevents duplicated entries.
class LockedFiles(PeeweeModel):
folder = peewee.CharField(index=True)
file = peewee.CharField(index=True)
#classmethod
def custom_init(cls):
db.execute_sql('create unique index if not exists lockedfiles_unique '
'on lockedfiles(folder collate nocase, file collate nocase)', {})
def create_tables(drop_existing_tables):
for table in [LockedFiles, Model2, Model3]:
if drop_existing_tables:
table.drop_table(True)
table.create_table(True)
try:
table.custom_init()
except:
pass
create_tables(drop_existing_tables=False)
You can specify a collation by building up the SQL clause and passing it to order_by().
For example:
collated = Clause(MyModel.field, SQL('COLLATE NOCASE'))
MyModel.select().order_by(collated, MyModel.other_field)
For the index unfortunately you will need to create that by hand as peewee does not know how to add collation information to the CREATE INDEX SQL. If you'd like to open a pull-request I would definitely consider merging that feature, though.
I have an existing database where they created theiw own unicode collation sequence. I'm trying to use the following code and get a "no such collation sequence" exception. Can anybdy hlep with the the syntax to use "collate nocase" with this code?
update Songs set
SongPath = replace (SongPath, 'Owner.Funkytown', 'Jim');
Dump database (via shell), edit output SQL (find and change column definitions, set COLLATION NOCASE). Recreate database.