Syntax error: Unclosed identifier literal at [2:2] - google-bigquery

CREATE TABLE
'bigquery-public-data.baseball.schedules_partitioned'
PARTITION BY
YEAR(year) AS
SELECT
*
FROM
`bigquery-public-data.baseball.schedules`
Some one help me clarify the error here.

Related

Execution error: [Vertica][VJDBC](4856) ERROR: Syntax error at or near "."

Trying to insert this activity into my table but getting the error seen below. Any thoughts? SQL query checkers keep telling me its in my insert statement but I'm not seeing any outlier on my end. Thanks!
INSERT INTO
"_CEL_MD_ACTIVITIES" ("_CEL_MD_ACTIVITIES"."CASE_KEY", "_CEL_MD_ACTIVITIES"."ACTIVITY_EN", "_CEL_MD_ACTIVITIES"."EVENTTIME")
SELECT
"_CEL_MD_CASE_TABLE"."CASE_ID" AS "_CEL_MD_ACTIVITIES"."CASE_KEY",
'Case Reopened' AS "_CEL_MD_ACTIVITIES"."ACTIVITY_EN",
"_CEL_MD_CASE_TABLE"."CASE_REOPEN_DATE" AS "_CEL_MD_ACTIVITIES"."EVENTTIME"
FROM
"_CEL_MD_CASE_TABLE"
JOIN
"_CEL_MD_ACTIVITIES"
ON "_CEL_MD_CASE_TABLE"."CASE_ID" = "_CEL_MD_ACTIVITIES"."CASE_KEY"
WHERE
"_CEL_MD_CASE_TABLE"."CASE_REOPEN_DATE" IS NOT NULL;
Execution error: [Vertica]VJDBC ERROR: Syntax error at or near
"."
You use as aliases the name and fields of a table involved in the join.
For example
AS "_CEL_MD_ACTIVITIES"."ACTIVITY_EN",
This is not correct. You should change your alias names and not use dots (.) in them or remove the usage of aliases

Create table from a table in SQL Server

Below is the query I tried to execute in SQL Server:
CREATE TABLE List
AS
(SELECT * FROM counts)
I get this error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '('
I did some research on google to understand and isolate the error, but, failed to do so. Could anyone please help me understand the error. Thank you
SQL-Server's syntax to create a table from a query is by adding an into clause:
SELECT *
INTO list
FROM counts

What's wrong with my sql in oracle?

What's wrong with my sql in oracle? There are some data in my table,I select all of them and I can get them.but I can not search them if I add a condition.When did I add single or double quotation marks in my sql?Now I find that when I write some search statement,I must add single quotation marks.And when I write some insert statement,I must add double quotation marks.Or my sql will run bad.How to judge when should I use the different quotation in my sql?
select * from T_STUDENT
and the result is:
sex(varchar2) phone(varchar2) birthtime(timestamp)
1 13553812147 2016-06-03 16:02:00.799 **
When I add a search condition,but the result is null.
//error:ORA-000904
select * from T_STUDENT where phone='13553812147'
//error:ORA-000904
select * from T_STUDENT where PHONE='13553812147'
//run well but result is null
select * from T_STUDENT where 'phone'='13553812147'
And the same question I meet in the insert statement.
//error:ORA-000904
insert into T_STUDENT (sex,phone,birthtime) values('1','12345645454','2016-06-04 16:02:00.799')
//error:ORA-000928 missing select keyword
insert into T_STUDENT ('sex','phone','birthtime') values('1','12345645454','2016-06-04 16:02:00.799')
//run well but must add double quotation marks
insert into T_STUDENT ("sex","phone","birthtime") values('1','12345645454','2016-06-04 16:02:00.799')
This is because your table was defined using double quotes around the column names:
create table t_student
( "sex" varchar2(1)
, "phone" varchar2(30)
, "birthtime" timestamp
);
Using double quotes makes the names case-sensitive and so for ever after they must be referenced in double quotes, since by default Oracle is nicely case-insensitive. For this reason you should never use double quotes when creating tables, views etc.
I've had the chance to look at this and Tony Andrews' answer is correct, you actually get invalid identifier as error message when you type an invalid column, which includes a case mismatch, though the error message will mention the exact identifier:
SQL> select * from T_STUDENT where phone='13553812147';
select * from T_STUDENT where phone='13553812147'
*
ERROR at line 1:
ORA-00904: "PHONE": invalid identifier
SQL> select * from T_STUDENT where funny_bunny='13553812147';
select * from T_STUDENT where funny_bunny='13553812147'
*
ERROR at line 1:
ORA-00904: "FUNNY_BUNNY": invalid identifier
The only thing missing from his answer is that Oracle will always make an internal cast to uppercase for any unquoted identifier, as the full error message illustrates. That's why phone='13553812147' won't match a column defined as "phone" (but "phone"='13553812147' will do).
Last but not least, single quotes define plain strings rather than object names so when you do this:
select * from T_STUDENT where 'phone'='13553812147'
... you aren't filtering by phone column at all. Instead, you have a constant condition that's always false (text "phone" equals text "13553812147").

invalid identifier

I am trying to run a query but for reason its keep giving me below error
ORA-00904: "DISTANCE_IN_METRES": invalid identifier
can someone please help to sort the issue, much appreciated for any help or guidance on this.
You can not use a column defined in a select clause in that same select clause. Logically a select clause is evaluated all at once. A simplified example:
select 1 as test, 2 * test from dual
ORA-00904: "TEST": invalid identifier
As kashi points out in a comment, DISTANCE_IN_METRES is referenced in the case expression following the definition of DISTANCE_IN_METRES in the same select clause, and this is where the error is coming from.

Selecting a column with period in the column name SQL Server

I am linked to a Proficy Historian that allows periods in the column names. Because the data is stored in a non DBMS format I can not use openquery to get the data because there is no set schema to the tables. So I must use four part name syntax to get the data. This example works:
SELECT * FROM iHist...[SELECT * FROM ihTrend]
but this fails with Incorrect syntax near '.'.
SELECT * FROM iHist...[SELECT [SERVER.pid_astatus[07][0].F_CV.Value] FROM ihTrend]
where SERVER.pid_astatus[07][0].F_CV.Value is the name of the column
This fails as well with Incorrect syntax near the keyword 'from'.
SELECT * FROM
iHist...[SELECT [SERVER.pid_astatus[[07]][[0]].F_CV.Value] from ihTrend]`
Any ideas on how I can make SQL Server see this as a column?
EDIT:
Martins suggestion of the right brackets to escape the brackets work only on the outside of the sql call
SELECT [SERVER.pid_astatus[07]][0]].F_CV.Value] FROM iHist...[SELECT * FROM ihTrend]
However it does not work inside Incorrect syntax near the keyword 'from'.
SELECT * FROM iHist...[SELECT [SERVER.pid_astatus[07]][0]].F_CV.Value] FROM ihTrend]
EDIT
SELECT * FROM iHist...[SELECT [SERVER.pid_astatus[07]][0]].F_CV.Value]] FROM ihTrend]
I had to escape the column escape :)
You only need to escape these ]
[pid_astatus[07]][0]].F_CV.Value]
This works for me
CREATE TABLE #t(
[pid_astatus[07]][0]].F_CV.Value] int
)
SELECT [pid_astatus[07]][0]].F_CV.Value]
FROM #t
(Edited to reflect new knowledge, if you like this vote for Martin Smith's answer instead!)
Escape the ] by doubling them:
SELECT * FROM
iHist...[SELECT [SERVER.pid_astatus[07]][0]].F_CV.Value] from ihTrend]
Based on your comment, try:
SELECT [SERVER.pid_astatus[07]][0]].F_CV.Value] FROM iHist...ihTrend