How to return columns with the same name as original table when creating function?

So I have this function: create function report (varchar) returns table ( id bigint, src_data_system_id int8 ) language plpgsql as $$ begin return query select id, src_data_system_id from process_log_objects plo where src_data_system_name = ‘somecondition’||$1; end $$ If in returns block I am using the same column names as in select query in a function body,… Read More How to return columns with the same name as original table when creating function?

Does it matter to filter results when doing aggregation?

I want to get my sales for each day which is located in my orders_summary table. orders_summary table columns: id, date, amount, sku_id products table columns: id, sku Currently Im getting my daily sales like this: SELECT MAX(CASE WHEN os.date = ’01/01/2022′ THEN COALESCE(amount,0)::INT ELSE 0 END) AS orders_1, MAX(CASE WHEN os.date = ’01/02/2022′ THEN… Read More Does it matter to filter results when doing aggregation?

postgress-node error: bind message supplies 1 parameters, but prepared statement "" requires 0

I’m doing a simple request to a database and trying to retrieve all the table data. However, i get this error: error: bind message supplies 1 parameters, but prepared statement "" requires 0 const { Client } = require(‘pg’); const client = new Client({ //connection details }); const query = async() => { await client.connect();… Read More postgress-node error: bind message supplies 1 parameters, but prepared statement "" requires 0

Referring alias from select sql query

select sum(case when oi.status = ‘LOADING’ or (oi.status = ‘SORTING’ and oi.type = ‘RELEASE_OF_GOODS’) then oi.release_qty else 0 end) as nonLoadedQty ,sum(case when oi.status = ‘LOADING’ or (oi.status = ‘SORTING’ and oi.type = ‘RELEASE_OF_GOODS’) then (oi.release_uom_value/oi.release_qty * oi.release_qty) else 0 end) as "nonLoadedUomValue" from tmp_data rih left join pallets plt on plt.id = rih.reusable_pallet_id inner… Read More Referring alias from select sql query

Group by event using row_number

I have this table: CREATE TABLE #Data ( Event_Date date, Person_ID varchar(1), Event_flag varchar(1) ) INSERT INTO #Data (Event_date, Person_ID, Event_flag) VALUES (‘20190910’, ‘A’, ‘X’), (‘20190911’, ‘A’, ‘X’), (‘20190912’, ‘A’, ‘Y’), (‘20190913’, ‘A’, ‘X’), (‘20190914’, ‘A’, ‘X’), (‘20190915’, ‘A’, ‘X’), (‘20190916’, ‘A’, ‘Y’) How to get result using row_number or loop, to get same row_numbers… Read More Group by event using row_number