I am trying to use sql function in my BigQuery query :
SELECT FORMAT("%T", NET.HOST(resolved_urls.url)) AS host, FROM [tableName] LIMIT 1000
But I get the following error:
Error: 2.15 - 2.55: Unrecognized function format
I am getting these error for every sql function i am trying to use.
Any Idea ? thank you
Those new functions are supported by BigQuery Standard SQL only
Try below
#standardSQL
SELECT FORMAT("%T", NET.HOST(resolved_urls.url)) AS host, FROM tableName LIMIT 1000
Also note: in Standard SQL you use `tableName` and not [tableName]
Related
I am using MS SQL Server Version 2008 and MariaDB 10.5.
My table and data :
Following is the query i am running on both the databases.
select distinct distributor from market order by city
Found this query is failing in MS SQL Server database with error
SQL Error [145] [S0001]: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
Understood the reason why it failing
Reason for - ORDER BY items must appear in the select list if SELECT DISTINCT is specified
when i ran the same query run with MariaDB it ran successful without any error and gave me below output.
So i have doubt why MariaDB is behave different here? ideally it should fail right?
Thanks in advance.
Please try this query
Select distinct col from (
Select col from table order by col
)
I got the SQL query from another developer and there was unix_timestamp function, because this query returns a list of objects from database in the exact period of time. Query doesn't work because of the SQL error 195: 'unix_timestamp' is not a recognized built-in function.
n.created>unix_timestamp('2019-02-28') and n.created<unix_timestamp('2019-09-01')
"unix_timestamp" is a built in function on MySQL - it isn't on SQLserver.
Here's the code to get the unix timestamp now:
SELECT DATEDIFF(SECOND,'1970-01-01', GETUTCDATE()) AS unix_timestamp
You can either create a user defined function to do this and use the query as-is or you can just modify the query like so:
n.created>(DATEDIFF(SECOND,'1970-01-01', '2019-02-28')) and n.created<(DATEDIFF(SECOND,'1970-01-01','2019-09-01'))
Unix timestamps are not particularly useful in SQL Server. You can add a computed column to convert this to a datetime data type:
alter table t add created_dt as (dateadd(second, created, '1970-01-01')) persisted;
create index t_created_dt on t(created_dt);
This then allows you to write:
n.created_dt > '2019-02-28' and
n.created_dt < '2019-09-01';
Otherwise, the solution by motobatsu is a good solution.
In BigQuery I am using the following query:
SELECT
*
FROM
`properati-data-public:properties_mx.properties_sell_201***`
WHERE
_TABLE_SUFFIX BETWEEN '1501'
AND '1810'
Where properati-data-public:properties_mx.properties_sell_201501 is a valid table. When I use the query with multiple tables, I get the following error:
Query Failed
Error: Invalid table name: `properati-data-public:properties_mx.properties_sell_201***`
you should use:
`properati-data-public.properties_mx.properties_sell_20*`
Note:
. vs. :
20* vs. 201***
Also put below as a first line in your query to assure you are in Standard SQL mode
#standardSQL
I wish to migrate from Legacy SQL to Standard SQL
I had the following code in Legacy SQL
SELECT
hits.page.pageTitle
FROM [mytable]
WHERE hits.page.pageTitle contains '%'
And I tried this in Standard SQL:
SELECT
hits.page.pageTitle
FROM `mytable`
WHERE STRPOS(hits.page.pageTitle, "%")
But it gives me this error:
Error: Cannot access field page on a value with type
ARRAY> at [4:21]
Try this one:
SELECT
hits.page.pageTitle
FROM `table`,
UNNEST(hits) hits
WHERE REGEXP_CONTAINS(hits.page.pageTitle, r'%')
LIMIT 1000
In ga_sessions schema, "hits" is an ARRAY (that is, REPEATED mode). You need to apply the UNNEST operation in order to work with arrays in BigQuery.
Firstly, I'm new to SQL - not so new to Java anymore.
Secondly, I'm using NetBeans 7.2.1 with JavaDB and when I'm trying to run a SQL query, such as:
SELECT * FROM mydatabase ORDER BY colname DESC LIMIT 0,1
and try to execute the commend, the console displays an error, namely:
Error code -1, SQL state 42X01: Syntax error: Encountered "limit" at line 1, column 55.
Any ideas on what I can do? Do you see something wrong with my query code?
Please consult the Derby FAQ at http://db.apache.org/derby/faq.html#limit
You can easily do it like this.
SELECT *
FROM mydatabase
ORDER BY colname DESC
FETCH FIRST 10 ROWS ONLY;
Reference