I would like to have date formatted like here on SO: "Feb 6, '14".
I cannot put the apostrophe there before the number 14.
I tried the following formatter strings:
{{model.since | date:'MMM d, \'yy'}}
{{model.since | date:'MMM d, 'yy'}}
{{model.since | date:"MMM d, 'yy"}}
{{model.since | date:"MMM d, 'yy"}}
The apostrophe is not displayed.
How can I put the apostrophe there?
From the documentation on date:
In order to output single quote, use two single quotes in a sequence (e.g. "h 'o''clock'").
Since a string literal must also be enclosed in single quotes, you need four single quotes in a row. And since you're using single quotes in your format, you need to enclose the entire format string with double quotes, rather than single quotes.
Thus, your formatter string should be {{model.since | date:"MMM d, ''''yy"}}
Related
I m new to snowflake.
Input String : ["http://info.wealthenhancement.com/ppc-rt-retirement-planning"]
Output String : info.wealthenhancement.com/ppc-rt-retirement-planning
Please help to get output string.
Thanks
Use the substr function to only take characters from the 8th character to the end:
select
'http://info.wealthenhancement.com/ppc-rt-retirement-planning' as orig_value,
substr(orig_value, 8) as new_value
The output is:
+-------------------------------------------------------------+-------------------------------------------------------+
|ORIG_VALUE | NEW_VALUE |
+-------------------------------------------------------------+-------------------------------------------------------+
|http://info.wealthenhancement.com/ppc-rt-retirement-planning | info.wealthenhancement.com/ppc-rt-retirement-planning |
+-------------------------------------------------------------+-------------------------------------------------------+
This will work for http and https URLs by splitting using // as a delimiter. Only the last statement is required. The other two show how it's done built into steps:
-- Set a session variable to the string
set INPUT_STRING = '["http://info.wealthenhancement.com/ppc-rt-retirement-planning"]';
-- Trim leading and trailing square brackets and double quotes
select (trim($INPUT_STRING, '"[]'));
-- Split using // as a delimiter and keep only the right part and cast as string
select split((trim($INPUT_STRING, '"[]')), '//')[1]::string as URL
Im trying to create a string recognition rule to run in flex,the string can consist of escape characters(\n , \t , \r , \ , " , '), symbols( -, +, *, /, :, _, $, !, #, #, &, ~, ^, (, ) ) and a-zA-Z0-9 characters,i have tried many variations of the code below,but i keep getting the same error mentioned above.
ESCAPECHAR [\n] | [\t] | [\r] | [\] | ['] | ["]
SYMBOLS [-+*/:_$!##&~^()]
CHARACTERS [0-9a-zA-Z]
STRING ("({ESCAPECHAR} | {SYMBOLS} | {CHARACTERS})*") | ('({ESCAPECHAR} | {SYMBOLS} | {CHARACTERS})*')
You would do well to read the Flex manual chapter on patterns syntax. It is not very long, and it gives a complete description of the syntax of Flex patterns.
Here are a few of the errors you have made:
Flex patterns cannot include unquoted whitespace (unless you put them inside of a subexpression marked with the x flag). So
[\n] | [\t] | [\r] | [\] | ['] | ["]
is invalid.
Also, the \ is used to indicate that:
the following letter is a code for a control character (so that \n is a newline character), or
the following punctuation symbol should not be given special significance.
So in [\], the \ indicates that the following ] should be treated as an ordinary character, instead of being the end of a character class, which means that the character class will continue up to the next ]. Space characters inside a character class are considered to be quoted, so the character class consists of the characters ], space, |, [ and '. (Flex lets you repeat characters inside a character class, so it won't complain about the fact that there are two space characters.) You probably meant [\\].
Anyway, you should write character classes in the same way you wrote the other character classes, as a series of characters or escaped codes inside [ and ]:
[\n\t\r\\ '"]
Flex lets you quote characters by surrounding them with quotation marks, so that `"({ESCAPECHAR} | {SYMBOLS} | {CHARACTERS})*" is treated as a single literal string, which must be matched literally in the text. You probably intended the quotation marks to be ordinary characters, so you should have escaped them or put them into a single-character character class:
["]({ESCAPECHAR}|{SYMBOLS}|{CHARACTERS})*["]
Again, it is necessary to remove the whitespace from the pattern.
I assume that your intention was to allow "escape characters" to appear in a string only if they are actually escaped. Your {ESCAPECHAR} macro expands to a collection of actual characters, so that it includes newline, tab and carriage return characters. It also includes quote and apostrophe, which really should be reserved for terminating the string literal. Probably, what you meant was to allow escape codes if they are preceded with a \ (as with C or, as mentioned above, flex itself). In that case, what you really need to write is
ESCAPECHAR \\[ntr'"]
(That is, a \\, followed by exactly on of the characters n, t, r, ', ".) Even that is not precise, though: It does not allow the use of \\ to indicate a single \, and it forces the user to write "Don\'t just copy code." and '\"', both of which would normally be written without the backslash escapes.
I had created a table in hive with ORC format and loaded data into the table. I have use collect_set to eliminate the duplicates as follows to insert the data. However, i see double quotes in the array. Is there anyway to remove those double quotes?
This is an sample data iim getting from table a and inserting into the table b using:
insert into table b
select a.name as name, collect_set(b.sub) as subjects from a group by a.name;
my table be would be like this:
name | subjects
john | ["Eng", "Math", "Phy"]
Sarah | ["Math", "Chem"]
I want to get ride of the double quote in the array to look like this:
name | subjects
john | [Eng, Math, Phy]
Sarah | [Math, Chem]
Is there anyway to do this using hql?
Array is an object and to be displayed it needs to be transformed to string.
When you select array, it is being transformed(serialized) to string. Hive displays array as comma separated values, double quoted, in square brackets.
Consider this example:
select array('Eng', 'Math', 'Phy');
Returns:
["Eng","Math","Phy"]
What I'm trying to say is that there is no double-quotes " in the initial data most probably, it is being serialized to String with double-quotes when you select it directly without explicit conversion to string.
If this is the real reason of double quotes in the select result, then the solution is to transform array to string explicitly:
select concat('[',concat_ws(',',array('Eng', 'Math', 'Phy')),']');
Returns:
[Eng,Math,Phy]
Is it what you expected?
If not and you really need to remove double-quotes from column value, then regexp_replace will do.
Example of array containing double quotes in the values:
select concat('[',concat_ws(',',array('"Eng"', '"Math"', '"Phy"')),']');
Returns:
["Eng","Math","Phy"]
In such case you can apply regexp_replace when loading your table
regexp_replace(string, '["]', '') --this will remove double-qutes
Your insert statement will look like this:
insert into table b select a.name as name, collect_set(regexp_replace(sub, '["]', '')) as subjects from a group by a.name;
When I execute this
select PATINDEX('%[0 ]%', '03/SI/00807/18-19')
I am getting 1.
By using ^ like this:
select PATINDEX('%[^0 ]%', '03/SI/00807/18-19')
I am getting 2.
[^] Allows you to match on any character not in the [^] brackets (for example, [^abc] would match on any character that is not a, b, or c characters) Whereas
[ ] Allows you to match on any character in the [ ] brackets (for example, [abc] would match on a, b, or c characters)
_ Allows you to match on a single character
% Allows you to match any string of any length (including zero length)
[^abcd] means: any one character EXCEPT a,b,c or d
select PATINDEX('%[0 ]%', '03/SI/00807/18-19')
The first character in your string which is (0 or space) is the 0 in the first place, so patindex returns 1.
select PATINDEX('%[^0 ]%', '03/SI/00807/18-19')
The first character in your string which is (neither 0 nor space) is the 3 in the second place, so patindex returns 2.
I'm using Go but I'm having issues while trying to get an array that contains a single quote, I'm making a query structure to create a .sql file with that query, the issue is with an array field that is adding double quotes instead of a single quote.
This is what I have:
Yaml File:
Name: 'Myname'
Age: 9
Dimensions ['go', 'lang']
Go code Syntaxis:
var Query string = "";
Query = fmt.Sprintf("INSERT INTO persons (name, age, dimensions) VALUES ('%s', %d, %q)")
OUTPUT:
Query:
INSERT INTO persons (name, age, dimensions) VALUES ('MyName', 9, ["go", "lang"])
I don't want "go" and "lang" double quoted, I want it as the YAML file came, with single quote.
Is supposed that "%q" escape the single quote...
any idea what to do?