temporary Table in hql - sql

my query is like : with bigQuery as ( ) select * from bigQuery ;
how to write it with HQL ??

You can't. HQL can be used with mapped tables only; you can't use it to create tables on the fly. Use native SQL if you need to do this. further info HERE

Related

Is there a way to view the query or last history in a BigQuery Table?

A coworker created a table in BigQuery using "create or replace table" function. Unfortunately the query wasn't documented. I was wondering if there's a way to see the underlying query behind the table or a way to access the edit history of the table?
Use below as an example
select ddl
from `bigquery-public-data.utility_us.INFORMATION_SCHEMA.TABLES`
where table_name = 'us_county_area'
with out put like below
There are quite a number of very usefull INFORMATION SCHEMA Views to use
I would try to find this query in INFORMATION SCHEMA JOBS:
SELECT * FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
WHERE
job_type = 'QUERY' and
statement_type = 'CREATE_TABLE_AS_SELECT' and
lower(query) LIKE '%create%table%foo%' -- replace foo with your table name

What's the hbase equivalent to the Oracle sample clause?

In Oracle you can take a sample of a dataset like so:
select * from table sample(10);
What's the equivalent to this in HBase?
No. There is no equivalent to Oracle's sample syntax.

SQL Where clause from a file on Oracle

I have a requirement to construct an SQL that has a where clause which is expected to look into a file entries to be used in that clause.
SELECT DISTINCT '/',t_05.puid, ',', t_01.puid,'/', t_01.poriginal_file_name
FROM PWORKSPACEOBJECT t_02, PREF_LIST_0 t_03, PPOM_APPLICATION_OBJECT t_04, PDATASET t_05, PIMANFILE t_01
WHERE t_03.pvalu_0 = t_01.puid AND t_02.puid = t_03.puid AND t_03.puid = t_04.puid AND t_04.puid = t_05.puid AND t_02.puid IN ( 'izeVNXjf44e$yB',
'gWYRvN9044e$yB' );
The above is the SQL query. As you can see the IN clause has two different strings ( puids ) that are to be considered. But in my case, this list is like 50k entries long and would come from splunk and will be in a text file.
Sample output of the text file looks as belows:
'gWYRvN9044e$yB',
'DOZVpdOQ44e$yB',
'TlfVpdOQ44e$yB',
'wOWRehUc44e$yB',
'wyeRehUc44e$yB',
'w6URehUc44e$yB',
'wScRehUc44e$yB',
'yzXVNXjf44e$yB',
'guWRvN9044e$yB',
'QiYRehUc44e$yB',
'gycRvN9044e$yB'
I am not an SQL guru, but a quick google on this gave me a reference to OPENROWSET construct, which is not available on Oracle.
Can you please suggest some pointers on what can be done to circumvent the problem.
Thanks,
Pavan.
Consider using an external table, SQL Loader or perhaps loading the file into a table in the application layer and querying it normally.
I would recommend creating a Global Temporary table, adding the rows to that table, and then joining to your temp table.
How to create a temporary table in Oracle
Other options:
You could also use pipelined functions:
https://oracle-base.com/articles/misc/pipelined-table-functions
Or use the with as... construct to fold the data into the SQL. But that would create a long SQL statement.

PostgreSQL SQL FOUND_ROWS SHOW TABLES

I want to change this SQL to PostgreSQL:
1- $result = $this->query('SELECT FOUND_ROWS() AS found');
2- $result = $this->query('SHOW TABLES');
If you are trying to get the equivalent sql code from MySQL to PostgreSQL:
I think there no direct statement/function of FOUND_ROWS(), but you can of course get it using a function for example.
To get the list of tables on postgreSQL similar to SHOW TABLES of MySQL, you can use:
SELECT * FROM pg_catalog.pg_tables

Oracle and Sybase compatibility for create table new_table as

I am trying to write an SQL query which needs to be compatible on both a Sybase and Oracle database. The query looks like the following :
SELECT *
INTO new_table
FROM other_table
This query is working great on a Sybase database but not on an Oracle one. I found the equivalent for Oracle :
CREATE table new_table AS
SELECT *
FROM other_table
Is there a way to write a third query that would do the same and that can be executed on a Sybase and on an Oracle database?
As you found, Oracle supports INTO but doesn't use it like Sybase/SQL Server do. Likewise, Sybase doesn't support Oracle's extension of the CREATE TABLE syntax.
The most reliable means of creating a table & importing data between the systems is to use two statements:
CREATE TABLE new_table (
...columns...
)
INSERT INTO new_table
SELECT *
FROM OLD_TABLE
Even then, syntax is different because Oracle requires each statement to be delimited by a semi-colon when TSQL doesn't.
Creating a table & importing all the data from another table is a red flag to me - This is not something you'd do in a stored procedure for a production system. TSQL and PLSQL are very different, so I'd expect separate scripts for DML changes.
There is no query that would do what you want. These environments are very different.
It is possible.
SELECT * INTO new_table FROM existing_table;
Thanks