Ask for advice
hive> select version();
OK
2.3.3 r95e2ca94dcfdc6c2f5435a3de4094e1ab0f39976
The field comments table displays question marks instead of Cyrillic ( which is where I write comments).
If comments are written in Latin letters, then everything is fine.
For example:
CREATE TABLE `test_com`(
`id` string COMMENT 'Test comment',
`di` string COMMENT Тест коммент'
) STORED AS ORC
TBLPROPERTIES ( 'store.charset'='UTF-8', 'retrieve.charset'='UTF-8');
=====>>>>
enter image description here
`id` string COMMENT 'Test comment',
`di` string COMMENT '???? ???????'
I tried different table formats and different ways to create it , but nothing helps.
Data in the table Cyrillic is displayed normally.
I tried changing comments via
ALTER TABLE test_com CHANGE id id STRING COMMENT 'Number of the house (hold)';
But it doesn 't help
How can I fix this?
Related
I didn't see any similar questions asked on this topic.
I have to write a sql query for selecting a field from table and then generating a string replacing space with '-' and putting in another field.
select title field and replace space with '-' and store in slug for all data
You need to use a REPLACE.
Use the following to test it
SELECT
ID
,Title
,REPLACE(title,' ','-') Slug
FROM tableName;
and if it is good, use the following to populate the field
UPDATE tableName
SET slug = REPLACE(title,' ','-');
Description: REPLACE will do exactly as it sounds, replace all instances of a character (or characters) with the replacement string which you provide.
Here's the link to SQL Server documentation (it's the same for MySQL as well - you have multiple RDBMS tags here): https://learn.microsoft.com/en-us/sql/t-sql/functions/replace-transact-sql?view=sql-server-ver15
#Rajat Singh. It seems to be simply:
update table
set slug = replace(title, ' ', '-')
Lets say I have a forum and I have a thread topic called "Game of Thrones"; and its stored just that way in the database. When someone wants to access it, the URL will look like: www.someforum.com/topics/game-of-thrones.
When searching, I can simply replace the hyphens with spaces, or ignore them, but it would create ambiguity between different permutations of words and hyphens for strings that have a both spaces and hyphens(e.g."Mother-In-Law Issues"). How can I handle this?
I thought of creating a "slug" column in the topic table which would contain the url for the topic title, and the "title" column would save the permutation of spaces and hyphens as intended by the user...
I think I got you now.
How about something like this (just a rough demo)? -
create table url (url_id int primary key,url varchar(1000));
insert into url (url_id,url) values (1,'www.someforum.com/topics/game-of-thrones');
create table search_term (search_term varchar(1000),url_id int references url(url_id));
insert into search_term values ('game of thrones',1),('GOT',1)
select u.url
from search_term as st
join url as u
on u.url_id =
st.url_id
where st.search_term = 'GOT'
;
I am attempting to load a tab delimited text file which contains a column of values which happen to look exactly like a date, but aren't. It appears that the CSVREAD command scans the row, converts the text value in the column to a java.Sql.Date, and then sees that the target column is a VARCHAR and executes toString() to obtain the value...which is exactly NOT what I need. I actually need the raw unconverted text with no date processing whatsoever.
So, is there some way to turn off "helpful date-like column conversion" in the CSVREAD command?
Here's the simplest case I can make to demonstrate the undesired behavior:
CREATE TABLE x
(
name VARCHAR NOT NULL
value VARCHAR
) AS
SELECT * CSVREAD('C:\myfile.tab', null, 'UTF-8', chr(9))
;
The file contains three rows, a header and two records of values:
name\tvalue\n
x\t110313\n
y\t102911\n
Any assistance on how I can bypass the overhelpful part of CVSREAD would be greatly appreciated. Thank you.
(It seems you found this out yourself, but anyway):
For CSVREAD, all columns are strings. The CSVREAD function or the database do not try to convert values to a date, or in any other way try to detect the data type. The database only does what you ask it for, which is read the data as a string in your case.
If you do want to convert a column to a date, you need to do that explicitly, for example:
CREATE TABLE x(name VARCHAR NOT NULL, value TIMESTAMP) AS
SELECT *
FROM CSVREAD('C:\myfile.tab', null, 'UTF-8', chr(9));
If non-default parsing is needed, you could use:
CREATE TABLE x(name VARCHAR NOT NULL, value TIMESTAMP) AS
SELECT "name", parsedatetime("value", "M/d/y") as v
FROM CSVREAD('C:\myfile.tab', null, 'UTF-8', chr(9));
For people who don't have headers in there csv files the example could be like this:
CREATE TABLE x(name VARCHAR NOT NULL, value TIMESTAMP) AS
SELECT "0", parsedatetime("1", 'd-M-yyyy') as v
FROM CSVREAD('C:\myfile.tab', '0|1', 'UTF-8', '|');
Beware of the single quotes around the date format. When I tried the example from Thomas it gave me an error using H2:
Column "d-M-yyyy" not found; SQL statement:
My csv files:
firstdate|13-11-2013\n
seconddate|14-11-2013
I would like to insert in a table some pieces of code. For example:
table:
create table [tbl_cfg](
[tabid] [int] IDENTITY(1,1) NOT NULL,
cust_code nvarchar(max) NULL
) ON [PRIMARY]
Insert into tbl_cfg(cust_code)
select ' this is the first line
this is the second line'
My problem is that when I do this, sql automatically flatterns my code i.e. any \n is replaced with spaces.
If I insert it with Edit top 200 rows and I just paste the code, only the first line is inserted.
UPDATE:
In order to test this:
select * from tbl_cfg
copy the code and paste it in another window
According my experience about this issue:
Your strings with \n is still in the original format in sql table, but when you do select it is presented in a single line.
However, for example if you put the string to html code, you'll see \n is still there.
check http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/
That's because you aren't seeing the result in text mode.
See this query and view the results with "Results to Text" checked and unchecked.
I have column with values that have wrong character ?. Now I want to change it to character b. For this I am using this statement:
SELECT REPLACE(name,'?','b') from contacts;
But when I do this nothing's happening, it return value with ?.
What I am doing wrong? How I can replace this?
Are you actually trying to change the values in the table? In that case, you'll need to do an UPDATE:
UPDATE contacts
SET name = Replace(name,'?','b')
Otherwise, if you are simply trying to retrieve a modified value, your syntax should work just fine. (I tested it, ? doesn't have to be escaped or anything):
SELECT name, Replace(name,'?','b') as Fixed
FROM contacts
Another possibility that I've seen before is that the character looks like a regular old ASCII question mark but it's not really. It's actually a different character. I'd select the text and paste it into Notepad and then copy and paste it into my query.
If your name column data type is NVARCHAR you should use N prefix. NVARCHAR and VARCHAR types have unicode differance. Look at this link for more information about differance between NVARCHAR and VARCHAR types.
SELECT REPLACE(name,N'?', N'b') from contacts;
Try this
update contacts set name=replace(name, '?', 'b')