I have a sql query in my R code:
query <- glue("SELECT
oper.value
oper.status
oper.class
FROM "uploads".ratings AS rates"
But i get this error:
Error: unexpected symbol in:
"oper.class
FROM "uploads"
How could i handle it? How should i write schema part in query?
It seems that r interprets the double quotes character as the end of the string. You would need to use an escape character to your query.
I think this should do it :
query <- glue("SELECT
oper.value
oper.status
oper.class
FROM \"uploads\".ratings AS rates")
Related
Postgres 14.
Are there any forbidden characters in aliasing columns?
I want to see '$' in column's name and it doesn't work. How can I get it done? Is there any magic function that could do that for me?
SELECT
id,
currency as '$',
available
from f_total
ORDER BY
id DESC
;
gives:
ERROR: syntax error at or near "'$'"
LINE 3: currency as '$',
^
SQL state: 42601
Character: 27
Same story when I use '€', '!', '<'. I expected it to be not executed against all syntax-verificators - it's just an insignificant string to be used on output ...
How to make my column to be named with such name?
Use double-quotes (") for identifiers:
currency AS "$"
See:
Are PostgreSQL column names case-sensitive?
Every string is allowed once double-quoted (with contained double-quotes doubled up). Doesn't mean it's a good idea to use "$" as identifier. It isn't.
I am trying to concat two columns with concat and concat_ws function. Along with concatinating two columns I also want to append a word to this concatination. So I tried to achieve that using below method
SELECT CONCAT(CONCAT("SRID=4326;POINT(", CONCAT_WS(" ",cast(A.longitude as string),cast(A.latitude as string))), ")") as the_geom
FROM test
With above syntax I am getting the following error.
**org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:13 cannot recognize input near 'CONCAT' '(' 'CONCAT' in expression specification**
I was not knowing what wrong I am doing in the above syntax. Is there any alternative way to achieve this.
Expected RESULT : SRID=4326;POINT(127.155104 35.8091378)
I tried all ways using concat and concat_ws, but getting syntax issues.
The problem is semicolon, it breaks the query. Try replacing semicolon with \073, also double backslash may work \\;
Also it seems single concat is enough.
Demo using \073 :
with test as (
select 12134.12345 as longitude, 12134.12345 as latitude
)
SELECT CONCAT("SRID=4326\073POINT(",
CONCAT_WS(" ",cast(A.longitude as string),cast(A.latitude as string))
, ")"
) as the_geom
FROM test A
Result:
SRID=4326;POINT(12134.12345 12134.12345)
I have a table and one of the columns is named CAST. How can I access this column. I've tried
Select [Cast] AS cast_s FROM tablename without success, Can I use this name or must I reimport all my data into bigquery?
I know that cast is a function. This is the error message:
Error:
Encountered " "CAST" "Cast "" at line 10, column 63. Was expecting: < E O F > (EOF has no spaces, markdown makes it disappear)
Thanks.
The lexical rules for BQ use backticks for this purpose:
select `cast` as cast_s
from tablename;
The documentation is here.
For BigQuery Legacy SQL you CAN use square brackets
SELECT [cast] as cast_s
FROM tablename
From documentation
You can use square brackets to escape reserved words so that you can
use them as field name and aliases. For example, if you have a column
named "prefix", which is a reserved word in BigQuery syntax, the
queries referencing that field will fail with obscure error messages
unless you escape it with square brackets:
SELECT [prefix] FROM ...
I have a SQLite table column holding MAC addresses.
How do I write the SQL where clause for a string value including a colon ':' character? Surrounding it with quote characters doesn't work.
So far, I've been getting this error:
android.database.sqlite.SQLiteException: near ":66": syntax error (code 1): , while compiling: SELECT * FROM PhoneStatus WHERE phoneDeviceId=00:66:4B:B2:7B:F5
Thanks!
You would seem to need single quotes for the string constant:
SELECT *
FROM PhoneStatus
WHERE phoneDeviceId = '00:66:4B:B2:7B:F5'
If the query is delimited by single quotes, then double them up or escape them somehow.
I would like to understand why this does not work :
select my_table.my_column AS 'what I want to write'
from my_table
The error:
ORA-00923: FROM keyword not found where expected
How do I name my column what I want to write ?
Thank you
Single quotes are for string literals, double quotes are for delimited identifiers, e.g. "what I want to write".