SELECT
metadata.field as something.field
FROM
tbl2
This query does not work because of the period in the "as" statement. If I remove it, the query will work fine. I cannot encapsulate something.field in quotes and I cannot seem to escape the dot. Does anyone know how to do so?
Use backticks (``) as in the following example:
create table papo1 as select date as `pi.po` from t1 ;
hive> describe papo1;
OK
pi.po string
Related
Is square bracket in table name, column name or datatype is not supported in postgresql ?
I am getting below error while running the query in pgadmin:
CREATE TABLE [Test];
ERROR: syntax error at or near "["
SQL state: 42601
In PostgreSQL you can use double quotes :
CREATE TABLE "Test";
Same for columns, square brackets are used in SQL-Server.
If you mean the table name would be [Test] with brackets included then you would use "[Test]".
Create table "[Test]" ...;
If you meant it as an identifier, you could simply use without brackets or double quotes as Test.
Create table Test ...;
This way, you could refer to it as Test or test or tESt without double quotes in subsequent queries, ie:
select * from test;
If you use "Test" then postgreSQL would treat it as case sensitive and you would always use "Test".
Create table "Test" ...;
If you were trying to emphasize the identifier name by using square brackets, then sagi's answer is correct. On the other hand, if you really want to use square brackets in your table name, postgresql supports this as "[Test]". In this case your table name will include square brackets. You can get additional info from postgresql documentation
I have a table called project-users and want to write a SQL query like SELECT * FROM project-users I get this error ERROR: syntax error at or near "-".
I cannot change the table name at this point.
According to http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html, you should use double quotes.
In your case, for PostgreSQL the query should be:
SELECT * FROM "project-users";
It is good practice to avoid the use of characters that need escaping or that contain spaces in identifiers.
I can't figure out which syntax to use for fields in my NexusDB that have spaces in them. I've tried the usual things like: [ ] `` but none of these work, the query just errors. So an example query might be:
select `offical name` from MyTable
select [official name] from MyTable
(these do not work)
Thanks,
Karl..
The delimiter for delimited identifiers according to ISO 9075 (aka the SQL standard) is a double quote. Which is what NexusDB implementes:
select "official name" from MyTable
According to this link, I should be able to use curly braces to escape an entire variable string. My understanding is that Oracle (10g or later -- I've been told we use 11g) should treat this (sanitized) SQL query:
SELECT * FROM customer WHERE name = 'Sam'
the same as it treats this one:
SELECT * FROM customer WHERE name = '{Sam}'
I tried it as a sanity check before trying strings that would actually need escaping, and it didn't work. The top query returns data, but the bottom doesn't. Am I doing something wrong?
SELECT * FROM customer WHERE name = q'{Sam}'
If a field value in the table of SQL Server is like A(B) and if I to write a query
SELECT * FROM MyTable WHERE MyField = 'A(B)'
it is not returning any result. How to handle this situation?
Your query should work fine, if you want to specify a different escape parameter, you can use ESCAPE.
WHERE column LIKE '%A#(B#)%' ESCAPE '#'
Also, if you want to match anything that contains "A(B)", don't forget to surround it by percetages symbols.