Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:04:27+00:00 2026-06-01T21:04:27+00:00

I have discovered a strange behavior in postgres’s crosstab function that I cannot explain,

  • 0

I have discovered a strange behavior in postgres’s crosstab function that I cannot explain, but hope someone else may…

The version of the crosstabs function I’m using requires first building a preliminary table.

This SQL successfully creates the preliminary table:

SELECT 
    ST.studyabrv||' '||S.labid||' '||S.subjectid||' '||S.box::varchar||' '||S.well AS "rowname",
    M.marker AS "bucket", 
    G.allele1||' '||G.allele2 AS "bucket_value" 
INTO TABLE ct 
FROM 
    geno.gmarkers M, 
    geno.genotypes G, 
    geno.gsamples S, 
    geno.guploads U, 
    geno.gibg_studies ST 
WHERE 
    G.markers_id=M.id 
    AND G.gsamples_id=S.id 
    AND S.guploads_id=U.id 
    AND U.ibg_study_id=ST.id 
    AND ( M.id=5 OR M.id=6 OR M.id=2 OR M.id=4 OR M.id=3) 
    AND ( S.labid='CL100001' OR S.labid='CL100002' OR S.labid='CL100003' OR S.labid='CL100004' OR S.labid='CL100005' OR S.labid='CL100006' OR S.labid='CL100007' OR S.labid='CL100008' OR S.labid='CL100009' OR S.labid='CL100010' OR S.labid='CL100011' OR S.labid='CL100012' OR S.labid='CL100013' OR S.labid='CL100014' OR S.labid='CL100015') 
ORDER BY box,well;

Which produces output like:

         rowname          |  bucket   | bucket_value 
--------------------------+-----------+--------------
 LTS CL100001 10011 1 A01 | 5HTTLPR-T | S La
 LTS CL100001 10011 1 A01 | 5HTTLPR-D | 14 16
 LTS CL100001 10011 1 A01 | DAT1      | 440 480
 LTS CL100001 10011 1 A01 | DRD4      | 475 475
 LTS CL100001 10011 1 A01 | Caspi     | 351 351
 LTS CL100009 10420 1 A02 | Caspi     |  
 LTS CL100009 10420 1 A02 | 5HTTLPR-T | La Lg
 LTS CL100009 10420 1 A02 | 5HTTLPR-D | 16 16
 LTS CL100009 10420 1 A02 | DAT1      | 440 480
 LTS CL100009 10420 1 A02 | DRD4      | 475 475
...

However, if I attempt to include a date column, which are all null, as in:

SELECT 
    ST.studyabrv||' '||S.labid||' '||S.subjectid||' '||S.box::varchar||' '||S.well||' '||G.run_date::text AS "rowname", 
    M.marker AS "bucket", 
    G.allele1||' '||G.allele2 AS "bucket_value" 
INTO TABLE ct 
FROM 
    geno.gmarkers M, 
    geno.genotypes G, 
    geno.gsamples S, 
    geno.guploads U, 
    geno.gibg_studies ST 
WHERE 
    G.markers_id=M.id 
    AND G.gsamples_id=S.id 
    AND S.guploads_id=U.id 
    AND U.ibg_study_id=ST.id 
    AND ( M.id=5 OR M.id=6 OR M.id=2 OR M.id=4 OR M.id=3) 
    AND ( S.labid='CL100001' OR S.labid='CL100002' OR S.labid='CL100003' OR S.labid='CL100004' OR S.labid='CL100005' OR S.labid='CL100006' OR S.labid='CL100007' OR S.labid='CL100008' OR S.labid='CL100009' OR S.labid='CL100010' OR S.labid='CL100011' OR S.labid='CL100012' OR S.labid='CL100013' OR S.labid='CL100014' OR S.labid='CL100015') 
ORDER BY box,well;

This produces the output:

 rowname |  bucket   | bucket_value 
---------+-----------+--------------
         | 5HTTLPR-T | S La
         | 5HTTLPR-D | 14 16
         | DAT1      | 440 480
         | DRD4      | 475 475
         | Caspi     | 351 351
         | Caspi     |  
         | 5HTTLPR-T | La Lg
         | 5HTTLPR-D | 16 16

As you can see, adding the run_date column to the end of the “rowname” composite column renders the entire composite blank…which is crazy.
If I populate run_date with dummy data, it will show up….but if it is blank or null, this causes the “rowname” to go blank.

I cannot tell if this is a bug in postgres, but it is a bizarre result that I would like to resolve, if possible.

TIA,
rixter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:04:28+00:00Added an answer on June 1, 2026 at 9:04 pm

    You should think of null as an unknown value. null values are not numbers or strings so you can’t opererate over them as if they were. So you should make sure you use some function that would return a non-null value, such as coalesce() that would return the first non-null parameter from left to right and force a default value as the right-most parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've discovered a strange behavior for mutable sets which I cannot understand: I have
I have an e-commerce application that is exhibiting strange behavior. The product is a
I have discovered how to paint but do not understand that Graphics is property
We have discovered that one of our auto generated assemblies is throwing a StackOverflowException
I have discovered that it is possible to populate resource strings with variable information
My testers have discovered that if you type free text into a file upload
I've been playing about with Runnable s and have discovered that if you postDelayed
While debugging an issue with our system, I have discovered a thread contention that
As well as my question Removing MKMapView Annotations causes leaks. I have discovered that
I have just discovered a variable name that is misspelled. If it were hidden

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.