Select field with Hyphen in Redshift Spectrum - amazon-web-services

I am trying to extract a nested field with an Hyphen in the name through Redshift Spectrum
SELECT mystruct.mysubstruct.my-field.id
FROM my_external_schema.my_table
I see in other DBMS is suggested to wrap the field name with double quotes:
"mystruct.mysubstruct.my-field.id"
or back ticks
`mystruct.mysubstruct.my-field.id`
but none of these worked for me.
Any suggesitons?

Since the double quotes permit to escape the special characters, doing "mystruct.mysubstruct.my-field.id" means that you are looking for the column named 'mystruct.mysubstruct.my-field.id' at top level and not as the nested column, because the dot is not used to extract the field.
What you have to do is
SELECT mystruct.mysubstruct."my-field".id
FROM my_external_schema.my_table

Related

Regex query to remove character(s) from lines that has a phrase

I'm trying to convert my DDL's from Oracle to Postgres but I'm having a problem with double quote characters. I want to remove double quotes from each and every line which contains "CREATE TABLE " phrase. For example I want this: CREATE TABLE "ILIKEMEMES" to be converted to this: CREATE TABLE ILIKEMEMES but I don't want line ("ID" VARCHAR(255) to change either. I'm doing this on Notepad++ so Python scripts wouldn't be my first choice of solution.
Try doing the following find and replace, in regex mode:
Find: \bCREATE TABLE "(.*?)"
Replace: CREATE TABLE $1
This will target only create table statements having a table name which appears in double quotes.

SQLite - display table names finishing by "_1"

I am looking for a way to display table names I have in a database for which the name is ending by "_1".
I tried to use the command:
.tables '%_1';
Unfortunately the underscore symbol is used in the expression matching, so it returned me tables such as:
"125_1","125_11","125_21".
Only the first one is interesting in this example, I will not display the full result because there are hundreds of tables. So I tried something like this:
.tables '%_1' ESCAPE '_';
And it gave me the exact same result.
If you have a solution to overcome the problem of the underscore symbol, please post it.
remember that I have hundreds of tables with names following this pattern in regex: "^\d+_\d+$"
This is not how the ESCAPE clause works. To search for an underscore, you must escape the underscore with the escape character:
LIKE '%#_1' ESCAPE '#'
Anyway, .tables is not an SQL command and ignores the ESCAPE clause. To do your own search, you have to run your own query:
SELECT name
FROM sqlite_master
WHERE type = 'table'
AND name LIKE '%#_1' ESCAPE '#';

Regex Nifi pass list of words in the table name pattern property

​How can I pass a list of table names to "CaptureChangeMySQL processor" that it should capture if any change happen to any table in that list? I tried few regex variations to accept a list of table names( e.g. Product and Order here), but no luck:
(?:^|(?<= ))(Product|Order)(?:(?= )|$)
(?:[\s]|^)(Product|Order)(?=[\s]|$)
^.*.(?Product$|Order$)[^.]+$
.\b(Product|Order)\b.
(Product|Order)
I think the table names regex you are looking for is
Product|Order
NiFi does not require or use a matching group in this style of filter.

How to trim non-numeric characters with APEX transformation

During importing a CSV file I want to transform one column with money values so that it will insert them into database without problem.
I have values such as "134,245.99 RUB" and the output should be "134,245.99" or "134245.99" at best.
I tried doing it using transformation but there is no documentation (sic!) on that subject from Oracle how to use it.
Do you have any ideas?
#tweant: You can use regexp_replace function and do this easily. Here's an example:
select trim(regexp_replace(' 2345abc ','\D*$','')) as str from dual;
This will remove all the non digit characters from the end and trim the white spaces.
More information about the function here.

replace headings in a word document

I am looking for a macro or way to replace all headings in a word document with one numeric value so that every heading at every level gets replaced with same numeric value.
Can anyone help?
It came out to be easy.
Use { SEQ heading } field. Copy the field code, select the destination format in Find and use ^c^p in replace. All headings with selected style will get the numeric value. Do the same for rest.