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

  • SEARCH
  • Home
  • 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 8705185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:17:46+00:00 2026-06-13T03:17:46+00:00

I have sql error null value in column kladr_full_name violates not-null constraint. Table in

  • 0

I have sql error null value in column “kladr_full_name” violates not-null constraint.

Table in database to wich request is performed:

СREATE TABLE kladr.kladr_name
(
  kladr_code character varying(255) NOT NULL,
  kladr_city_name character varying(121),
  kladr_full_name character varying(487) NOT NULL,
  kladr_index character varying(6),
  kladr_name character varying(100) NOT NULL,
  kladr_naspunkt_name character varying(121),
  kladr_rayon_name character varying(121),
  kladr_region_name character varying(121),
  kladr_socr character varying(20),
  CONSTRAINT kladr_name_pkey PRIMARY KEY (kladr_code )
)
WITH (
  OIDS=FALSE
);
ALTER TABLE kladr.kladr_name
  OWNER TO postgres;

Request to db:

    INSERT INTO kladr.kladr_name 
            (kladr_code, 
             kladr_name, 
             kladr_socr, 
             kladr_index, 
             kladr_region_name, 
             kladr_rayon_name, 
             kladr_city_name, 
             kladr_naspunkt_name, 
             kladr_full_name) 
SELECT kladr_code, 
       Upper(kladr_name)                 kladr_name, 
       kladr_socr, 
       kladr_index, 
       (SELECT k1.kladr_socr 
               ||' ' 
               ||k1.kladr_name 
        FROM   kladr.kladr_tmp k1 
        WHERE  k1.kladr_region = k.kladr_region 
               AND k1.kladr_rayon = '000' 
               AND k1.kladr_city = '000' 
               AND k1.kladr_nas_punkt = '000' 
               AND k1.kladr_mod = '00' 
               AND k1.kladr_status = '0')kladr_region_name, 
       (SELECT k1.kladr_socr 
               ||' ' 
               ||k1.kladr_name 
        FROM   kladr.kladr_tmp k1 
        WHERE  k1.kladr_region = k.kladr_region 
               AND k1.kladr_rayon = k.kladr_rayon 
               AND k1.kladr_rayon <> '000' 
               AND k1.kladr_city = '000' 
               AND k1.kladr_nas_punkt = '000' 
               AND k1.kladr_name = '00') kladr_rayon_name, 
       (SELECT k1.kladr_socr 
               ||' ' 
               ||k1.kladr_name 
        FROM   kladr.kladr_tmp k1 
        WHERE  k1.kladr_region = k.kladr_region 
               AND k1.kladr_rayon = k.kladr_rayon 
               AND k1.kladr_city = k.kladr_city 
               AND k1.kladr_city <> '000' 
               AND k1.kladr_nas_punkt = '000' 
               AND k1.kladr_mod = '00')  kladr_city_name, 
       (SELECT k1.kladr_socr 
               ||' ' 
               ||k1.kladr_name 
        FROM   kladr.kladr_tmp k1 
        WHERE  k1.kladr_region = k.kladr_region 
               AND k1.kladr_rayon = k.kladr_rayon 
               AND k1.kladr_city = k.kladr_city 
               AND k1.kladr_nas_punkt = k.kladr_nas_punkt 
               AND k1.kladr_nas_punkt <> '000' 
               AND k1.kladr_mod = '00')  kladr_naspunkt_name, 
       (SELECT k1.kladr_socr 
               ||' ' 
               ||k1.kladr_name 
        FROM   kladr.kladr_tmp k1 
        WHERE  k1.kladr_region = k.kladr_region 
               AND k1.kladr_rayon = '000' 
               AND k1.kladr_city = '000' 
               AND k1.kladr_nas_punkt = '000' 
               AND k1.kladr_mod = '00' 
               AND k1.kladr_status = '0') 
       ||' ' 
       ||(SELECT k1.kladr_socr 
                 ||' ' 
                 ||k1.kladr_name 
          FROM   kladr.kladr_tmp k1 
          WHERE  k1.kladr_region = k.kladr_region 
                 AND k1.kladr_rayon = k.kladr_rayon 
                 AND k1.kladr_rayon <> '000' 
                 AND k1.kladr_city = '000' 
                 AND k1.kladr_nas_punkt = '000' 
                 AND k1.kladr_mod = '00') 
       ||' ' 
       ||(SELECT k1.kladr_socr 
                 ||' ' 
                 ||k1.kladr_name 
          FROM   kladr.kladr_tmp k1 
          WHERE  k1.kladr_region = k.kladr_region 
                 AND k1.kladr_rayon = k.kladr_rayon 
                 AND k1.kladr_city = k.kladr_city 
                 AND k1.kladr_city <> '000' 
                 AND k1.kladr_nas_punkt = '000' 
                 AND k1.kladr_mod = '00') 
       ||' ' 
       ||(SELECT k1.kladr_socr 
                 ||' ' 
                 ||k1.kladr_name 
          FROM   kladr.kladr_tmp k1 
          WHERE  k1.kladr_region = k.kladr_region 
                 AND k1.kladr_rayon = k.kladr_rayon 
                 AND k1.kladr_city = k.kladr_city 
                 AND k1.kladr_nas_punkt = k.kladr_nas_punkt 
                 AND k1.kladr_nas_punkt <> '000' 
                 AND k1.kladr_mod = '00')kladr_full_name 
FROM   kladr.kladr_tmp k 
WHERE  k.kladr_mod = '00' 

DB postgreSql. jpa prov hibernate. What could be the reason of this?

Question now is how to modify this query to work in postgres(before it was working in oracle db) if some subquerys returns null?

  • 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-13T03:17:48+00:00Added an answer on June 13, 2026 at 3:17 am

    In PostgreSQL, an expression of the form a || b will evaluate to NULL if either of its arguments is NULL. So, your INSERT statement will try to insert NULL into kladr_full_name if any of those subqueries fails to find a record. You need to try each of those subqueries separately, and see which one is not giving you a record (or is giving you a record with NULL).


    Edited to add in response to OP comment: In Oracle, there’s no concept of zero-length strings, because they’re converted to NULL (so, for example, '' = '' is not true, whereas '' IS NULL is). Usually the conversion is one-way — LENGTH('') IS NULL — but in the case of the || operator, it converts NULL back to a zero-length string, such that 'ab' || NULL || 'cd' is 'abcd'. PostgreSQL doesn’t do this conversion automatically, because it does distinguish '' from NULL, but you can either:

    • perform this conversion explicitly by using the COALESCE function (documented in §9.17 “Conditional Expressions” of the PostgreSQL 9.2 Manual): COALESCE(NULL, '') evaluates to ''; or
    • use the CONCAT function (documented in §9.4 “String Functions and Operators” of the PostgreSQL 9.2 Manual) instead of the || operator. The CONCAT function simply skips over any NULL arguments, so CONCAT('ab', NULL, 'cd') evaluates to 'abcd'. However, this function is only available starting in PostgreSQL 9.x, so if you’re using PostgreSQL 8.x or older, you’ll need to use the COALESCE approach.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a column in SQL to be decimal(4,1), null which means I
I have a non-nullable database column which has a default value set. When inserting
I have a USER table in database. The table has a RegistrationDate column which
I have the following SQL and i want the order_item_wo_id column to return null
For example I have NOT NULL field in database. I'm trying to insert NULL
I am using SQL Server 2008r2. I have a table with a column defined
I'm having an sql error that i can't work out. I have to update
I most likely have a syntax issue (SQL command and error copied below) -
You have an error in your SQL syntax; check the manual that corresponds to
I get: You have an error in your SQL syntax; check the manual that

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.