Is there in BigQuery a way to include special characters (such as %, white space, periods etc) in column names, resp. can you somehow escape special characters?
In my case it would come in handy when col names would be more readable for example when exporting reports.
No, the rules for field names (and aliases) in BigQuery are:
A column name must contain only letters (a-z, A-Z), numbers (0-9), or
underscores (_), and it must start with a letter or underscore. The
maximum column name length is 300 characters. A column name cannot use
any of the following prefixes: _TABLE_, _FILE_, _PARTITION_.
Duplicate column names are not allowed even if the case differs. For example, a column named Column1 is considered identical
to a column named column1.
Related
I'm using oracle and hive db engine and supposed that in a varchar column (phone number), I only want to retrieve record with digit and hyphen '-'
i.e. 03-1234 5678
But how if I want to retrieve if column has special chars (except hyphen) and alphabet using like or rlike.
i.e 03-ABC123$#45XYZ or 03-AB123 Y123#& (with space)
Thanks in advance!
Using RLIKE we can try:
SELECT * FROM yourTable WHERE phone RLIKE '^[0-9 -]+$';
This will match only phone numbers consisting of digits, space, or hyphen.
I have a problem with querying in Japanese, what should I do?
SELECT current_date() AS 時間;
Error
Invalid field name "時間". Fields must contain only letters, numbers, and underscores, start with a letter or underscore, and be at most 300 characters long.
Currently table names and column names are English-only.
As stated in the documentation:
A column name must contain only letters (a-z, A-Z), numbers (0-9), or
underscores (_), and it must start with a letter or underscore. The
maximum column name length is 300 characters. A column name cannot use
any of the following prefixes: TABLE, FILE, PARTITION. Duplicate
column names are not allowed even if the case differs. For example, a
column named Column1 is considered identical to a column named
column1.
Therefore, other characters including japanese cannot be used as column names.
More info: https://issuetracker.google.com/65034056
I have above entries in my database, my requirement is to extract the fields containing the non-english language characters ( including if the data containing the combination of english and non-english characters like HotelName field for the ID 45).
I tried by regexp_like function by looking for the alphanumeric and non-alphanumeric, but i have some data with combination of both the condition fails there.
Thanks in Advance
Raghavan
Does this do what you want?
where regexp_like(hotelname, '[^a-zA-Z0-9 ]')
That is, where the hotel name contains any character that is not a "letter" or digit. You may need to take additional characters into account as well, such as commas, periods, and hyphens.
I want to find all rows for which values in string column does not possess certain characters (to be specific [a-Z0-9 \t\n]) how can I do it in sql ?
I tried to do it with like operator
SELECT ***
where column like '%[^ a-Z0-9 \t\n]%'
however, it does not work and I get rows that possess characters and numbers.
To fetch all records that contain any characters other than alphabets, numbers, spaces, tabs and new-line delimiters:
SELECT ***
WHERE column like '%[^A-Za-z0-9 \t\n]%'
Note that [^A-Za-z0-9 \t\n] represents anything other than alphanumeric characters, spaces, tabs, and new line delimitters.
Your logic is inverted. I think you want:
where column not like '%[^ a-Z0-9 \t\n]%'
I don't think that SQL Server interprets \t and \n as special characters. You may need to insert the actual values for the characters. (See here.)
SELECT ***
WHERE column like '%[^A-Za-z0-9 \t\n]%'
I have a column error_desc with values like:
Failure occurred in (Class::Method) xxxxCalcModule::endCustomer. Fan id 111232 is not Effective or not present in BL9_XXXXX for date 20160XXX.
What SQL query can I use to display only the number 111232 from that column? The number is placed at 66th position in VARCHAR column and ends 71st.
SELECT substr(ERROR_DESC,66,6) as ABC FROM bl1_cycle_errors where error_desc like '%FAN%'
This solution uses regular expressions.
The challenge I faced was on pulling out alphanumerics. We have to retain only numbers and filter out string,alphanumerics or punctuations in this case, to detect the standalone number.
Pure strings and words not containing numbers can be easily filtered out using
[^[:digit:]]
Possible combinations of alphanumerics are :
1.Begins with a character, contains numbers, may end with characters or punctuations :
[a-zA-Z]+[0-9]+[[:punct:]]*[a-zA-Z]*[[:punct:]]*
2.Begins with numbers and then contains alphabets,may contain punctuations :
[0-9]+[[:punct:]]*[a-zA-Z]+[[:punct:]]*
Begins with numbers then contains punctuations,may contain alphabets :
-- [0-9]+[a-zA-Z][[:punct:]]+[a-zA-Z] --Not able to highlight as code, refer solution's last regex combination
Combining these regular expressions using | operator we get:
select trim(REGEXP_REPLACE(error_desc,'[^[:digit:]]|[a-zA-Z]+[0-9]+[[:punct:]]*[a-zA-Z]*[[:punct:]]*|[0-9]+[[:punct:]]*[a-zA-Z]+[[:punct:]]*|[0-9]+[a-zA-Z]*[[:punct:]]+[a-zA-Z]*',' '))
from error_table;
Will work in most cases.