Code Monkey home page Code Monkey logo

colpivot's Issues

exception encountered Values [well100] cannot be coerced to []

Hi,
I'm using this function with postgres vertex reactive client. vertx-pg-client.

I'm trying to call this function with parameter but I get cannot be coerced to [] exception,

Can you guide me how can I resolve this issue.

public Completable testStreamWideTagHistoryv1(HistoryReqModel req) {
        logger.info("doing stream wide tag query");

        return txBegin()
                .flatMapCompletable(tx -> 
                    tx.rxPreparedQuery(
                        "select colpivot('test_output', 'select rt.v as agg_v, rt.t as bucket, rt.tag_id as tagged from rtdata rt where rt.asset_name = $1 ' "
                                + ", array['bucket'], array['tagged'], '#.agg_v', null)",
                        Tuple.of(req.getAssetName()))
                    .flatMapCompletable(result -> tx.rxCommit()));
    }

duplicates rows

Hi there. Nice function. Just found it on Stackoverflow...
However, I get duplicate rows in some cases. Unfortunately I could not create a test case... My query:

select colpivot('_test_pivoted', 'select * from input_data.building_elements',
array['type','constr_style'], array['year'], '#.market_share', null);

select * from _test_pivoted order by type, constr_style;

Any hints would be appreciated.

Returning the select statement or temp table vs. void

I am trying to use this package, but I am running into complications.

Mainly, the colpivot function returns multiple results. Is there a way to isolate the results that are returned?

i.e if I do this...

select colpivot(params) ---> returns temp_table
select * from temp_table
END TRANSACTION

It will return multiple results --- one for colpivot and one for the temp_table.

If I try this...

with cte as (SELECT colpivot(params), * from some_table 
LEFT JOIN some_table on temp_table)
END TRANSACTION

It will not allow the left join because the table does not exist before the query begins.

The only thing I can think is to modify what is being returned from the function. However, I have no idea the return type because the columns are dynamic.

Column / field names with blank spaces

Great function! If the column to be pivoted contains blank spaces the function returns an empty set. If you would include double quotation marks in line 30:

 query := query || 'quote_literal("' || quote_ident(col) || '")' 

this issue can be circumvented.

execute in one single statement

from this code
`select * from colpivot('_output', $$
select "StudentEnrollmentID" as a,value, name, "ComponentID" as q, "order" as o
from "university"."CourseSchedulledAssessmentComponent"
LEFT JOIN "university"."AssessmentResultPerComponent" ON "AssessmentResultPerComponent"."ComponentID" = "university"."CourseSchedulledAssessmentComponent"."ID"
where "CourseSchedulledAssessmentComponent"."UniversityID" = 1001 AND "CourseSchedulledAssessmentComponent"."CourseSchedulledID" = 1008
$$, array['a'], array['q'], '#.value', 'sum(o) asc');

select * from _output
`
is it possible to execute this in single statement?
Thanks

Error when querying an empty table

Hi, I really appreciate your work since it has solved a problem at my company in which we also needed to pivot an undefined number of results to columns.

Right now I am trying to investigate how can I avoid an ERROR when the table that I am querying is empty:

ERROR: upper bound of FOR loop cannot be null CONTEXT: PL/pgSQL function colpivot(character varying,character varying,character varying[],character varying[],character varying,character varying) line 67 at FOR with integer loop variable

Can you give any help with this ?

Mixed-case columns

It would be good to include a note in the README about mixed-case columns.

The code does double-quote column names, so mixed-case columns can be used.

However, there are two cases where the user has to do the quoting themselves.

  • value_e
  • col_order

Example cross-tabulating grading results by lesson:

SELECT colpivot(
	'_test_pivoted', 
	'select * FROM n_correct_for_course_by_lesson_s(''ANON'')', 
	array['userCode'], 
	array['lessonCode'],
	'#."percentCorrect"',
	'MAX("lessonOrder")'   -- bizarre syntactical requirement
);
select * from _test_pivoted ORDER BY "userCode";

The temporary table doesn't create

Hi,

I tried with the sample attached in documentation but it doesn't work for me. The table didn't create.
PostgreSQL 9.5.5 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609, 64-bit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.