SQL(ite) where clause with a colon (:) character - sql

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.

Related

Postgres doesn't let me use '$' in column alias

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.

How to concat two string with addon word to the column value in HIVE

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)

Strange symbol error in sql query with quotation marks

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")

Aliases for sql column

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".

Invalid column name when selecting

I have a table called Jobs with the following column names: JobID, Name, and Value. The table is filled like just one entry: JobID: 1, Name: TestJob, Value: 10
I want to do select * from Jobs where Name="TestJob", but this gives me an error saying "Invalid column name 'TestJob'". Why can't I select by the value of the Name column? Doing JobID=1 or Value=10 will give me the proper result.
Use single quotes instead of double quotes. Single quotes are the standard for SQL string and date constants:
select *
from Job
where Name = 'TestJob';
Some databases do accept double quotes for this purpose. It is always safest to use single quotes for string and date constants and double quotes to escape identifier names (if needed).
Change your double quotes " to single quotes '. Double quotes are used to surround object names, probably in the same way [] can be used, so you can have spaces and other normally-invalid object name characters in the object name. Single quotes, on the other hand, are used for string literals.
Use ' instead of ". It will work.