"org.netezza.error.NzSQLexception:ERROR " >>Telend to NETEZZA group by / subquery error - talend

I am trying to add component 'tNetezzainput' in Talend
with query like
select col1,col2 from
(select col1,col2 from tab2 )
when i run sub query independently it is allowing to get schema
but when i run above query it is showing error like
org.netezza.error.NzSQLexception:ERROR
(above query)

You need to add an alias after the parentheses (I randomly chose ‘x’):
select col1,col2 from
(select col1,col2 from tab2 ) x

Related

Loaded multiple files in table and now want to find Min and Max value is coming from which file

I have loaded multiple files in SQL Server.
Let's Say
table structure
Now
select COL_A, min(COL_C),max(COL_C)
from tbl
group by COL_A
I want to write SQL query to find which file has that Min(COL_C) and Max(COL_C) value. As you can see I am storing FILENAME in table.
So I want result like this
Here's one possible way you could get your results, using apply to correlate each aggregated value back to the same table to find the filename for that value, and using string_agg to produce a delimeted list if there are ties.
select * from (
select COL_A, Min(COL_C) MinColC,Max(COL_C) MaxColC
from T
group by COL_A
)x
outer apply (
select string_agg([filename], ', ') sMinFilename
from T
where T.COL_A=x.COL_A and T.COL_C=x.MinColC
)mn
outer apply (
select string_agg([filename], ', ') MinFilename
from T
where T.COL_A=x.COL_A and T.COL_C=x.MaxColC
)mx

count distinct concat in BigQuery

I have tried PostgreSQL:count distinct (col1,col2,col3,col4,col5)
in BigQuery :Count distinct concat(col1,col2,col3,col4,col5)
My scenario is I need to get same result as PostgreSQL in BigQuery
Though this scenario works on 3 columns ,I am not getting same value as PostgreSQL for 5 columns.
sample query:
select col1,
count(distinct concat((col1,col2,col3,col4,col5)
from table A
group by col1
when I remove distinct and concat, simple count(col1,col2,col3,col4,col5) gives exact value as populated in PostgreSQL. But i need to have distinct of these columns. Is there any way to achieve this? and does bigquery concat works differently?
Below few options for BigQuery Standard SQL
#standardSQL
SELECT col1,
COUNT(DISTINCT TO_JSON_STRING((col1,col2,col3,col4,col5)))
FROM A
GROUP BY col1
OR
#standardSQL
SELECT col1,
COUNT(DISTINCT FORMAT('%T', [col1,col2,col3,col4,col5]))
FROM A
GROUP BY col1
An alternative suitable for the many databases that don't support that form of COUNT DISTINCT:
SELECT COUNT(*)
FROM (
SELECT DISTINCT Origin, Dest, Reporting_Airline
FROM `fh-bigquery.flights.ontime_201908`
WHERE FlightDate_year = "2018-01-01"
)
My guess on why CONCAT didn't work in your sample: Do you have any null columns?

Multiple Selection in Datagrip (Running a CTE that's not in your nested query)

I'm looking for a way to run a nested correlated query that requires a CTE created above the script. For example if I had:
with first_cte as (
select *
from a_table
where 1=1
)
select * from
(select
column_1,
column_2,
column_3
from b_table b
inner join first_cte f on f.user_id = b.user_id
where 1=1) x
If I just wanted to test the nested query, it will say that first_cte doesn't exist. Is there a way to highlight the CTE so that it will run when I'm testing nested queries?
I'm using PostgreSQL btw. Thanks!!!
There are Execute selection and Execution options features in DataGrip.

selecting a distinct column with alias table not working in postgres

SELECT pl_id,
distinct ON (store.store_ID),
in_user_id
FROM plan1.plan_copy_levl copy1
INNER JOIN plan1._PLAN_STORE store
ON copy1.PLAN_ID = store .PLAN_ID;
while running this query in postgres server i am getting the below error..How to use the distinct clause..in above code plan 1 is the schema name.
ERROR: syntax error at or near "distinct" LINE 2: distinct ON
(store.store_ID),
You are missing an order by where the first set of rows should be the ones specified in the distinct on clause. Also, the distinct on clause should be at start of the selection list.
Try this:
SELECT distinct ON (store_ID) store.store_ID, pl_id,
in_user_id
FROM plan1.plan_copy_levl copy1
INNER JOIN plan1._PLAN_STORE store
ON copy1.PLAN_ID = store .PLAN_ID
order by store_ID, pl_id;

Postgres JDBC Numbered Parameters

I have a table in a Postgres 9.3 database with a json column like this:
CREATE mytable (
mycolumn json
)
I would like to execute queries from a Java application that look like this:
SELECT
mycolumn->>'somefield',
count(*)
FROM
mytable
GROUP BY
mycolumn->>'somefield'
When I try to use a PreparedStatement like this:
SELECT
mycolumn->>?,
count(*)
FROM
mytable
GROUP BY
mycolumn->>?
I get the following error:
PSQLException: ERROR: column "mytable.mycolumn" must appear in the GROUP BY clause or be used in an aggregate function
It makes sense that this happens because Postgres cannot guarantee that the two positional parameters are the same.
Using psql, I can prepare a statement like this:
PREPARE mystatement AS
SELECT
mycolumn->>$1,
count(*)
FROM
mytable
GROUP BY
mycolumn->>$1
Is it possible to do this with JDBC?
No, this isn't possible. JDBC only has positional parameters, and therefor the PostgreSQL driver will render it as:
PREPARE mystatement AS
SELECT
mycolumn->>$1,
count(*)
FROM
mytable
GROUP BY
mycolumn->>$2
And as the value of $1 is not necessarily the same as $2, the parser of PostgreSQL will reject it as you are potentially not grouping on the same column.
The solution might be to do:
SELECT a.aColumnLabel, count(*)
FROM (
SELECT mycolumn->>? as aColumnLabel
FROM mytable
) a
GROUP BY a.aColumnLabel