Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w79jX-0050ok-2Y for pgsql-novice@arkaria.postgresql.org; Mon, 30 Mar 2026 10:20:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w79jV-002UYy-0Y for pgsql-novice@arkaria.postgresql.org; Mon, 30 Mar 2026 10:20:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w79jU-002UYo-2Z for pgsql-novice@lists.postgresql.org; Mon, 30 Mar 2026 10:20:33 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w79jT-00000001mlQ-1xCU for pgsql-novice@lists.postgresql.org; Mon, 30 Mar 2026 10:20:32 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-c763c294cccso2953015a12.1 for ; Mon, 30 Mar 2026 03:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774866030; cv=none; d=google.com; s=arc-20240605; b=Rm/eHaAQvdmBCB0VELTq6f+hCeAMB0vTtgPJ0rl2qLDw/0iNgWvBLxryfemftKo6/W Zo1d17qmXZr+5GcDRDk86KLHXpwRVQRQIF8GrAoxVDQgCrtMFKDgvOxyfyjijkESbeZE NM1rOq89qFd5vfZnsSO8xcogfJ1MRsyL2gdQWUc+fkPXC/GR9gH3hWxwUvq2Nli2ioPt bPrA1yiixy0tjAvkPs3WeUlBMcEfgzig1jrfDw6Moisg2pMw0UH4/SgMwfVC8Ev/iCPg v92jj5sjNUxdzfK42EAzpxXst53Ohe+LERSztni5gEPuqNn/nUjy+WhrnTmvRoSms3TI qn2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=nu7DFgx8EtLxzgRunPMV0vfT1Jvq3dv3MOR+06hjz0c=; fh=tzCViSdjpELPlhoCp6KiPIestSyObL6AZvNc5NGKktU=; b=O/0Q5p5WtRR+1JmUiefDab+6SOhJOA22W2gza4Aqdtx3rHw5BRouqG8CbUFsRq9LCy 9U9u0OvgTOufEQPVCgj4xjz3tpoUDfjmQdPe6/2oUFmsgls3yot2tolDzbkFboAAfCrM nuimUqXoqDa1EdbgNgl22LaTK2u4LdWW52Pcav0Wml6KsVIGzCzpn20VC7UBJn3AxzQ7 mNERxU+DbmQdfwX8z7fiidXd4ZhaqefCbyroaltkysMiZ42HJzcyfjtsKS3hTTmnoh2R eKjoaZ2sEnEVSTq3zRDvrR/6w2YIkoYWgsdNtg75qUXkt8lnEH36HqOFGPDlX7c9AtBg duyA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774866030; x=1775470830; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=nu7DFgx8EtLxzgRunPMV0vfT1Jvq3dv3MOR+06hjz0c=; b=Gw7xh6CGVOvHasuOOtqRf4Wzag1arGcCYPVFEG40d0izIoW2qzn2IzJg9RuwrUITSl 2jQxaAUiP9N+31gC1h1P9RkU9mUESIFNGOVgBEgSBDmdPB+YcgrW329PoWlDgJcJcQIY U7bA4vv49Ok5TfuMKEiQb9Xxu4GGM9M2mEGic/oqyw2gPAVsNpslkzzmJ/4yc0QyKX7j O9xOxfWBQPf/nAXyfJ+IUNJBiRWsaPyUKa/LMy+vrn7yqjsYVcwtVMQnjTx7EEadBZKW 7qWmPHk0COmBu+v85q4CA6hf1zAgP/m3TspTkbek8yTTTkMndoKfaOqhSmgxHswnvQh2 bYNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774866030; x=1775470830; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nu7DFgx8EtLxzgRunPMV0vfT1Jvq3dv3MOR+06hjz0c=; b=CbrrLA/1rJMXJsoJaNP75flb9KfZw89hVh/eSH4M7xaIbQS7X1pra9gae3exDM3BI5 o1Y7XCFa0Csd2qmYAB8HIWs8Pk6YlpFXpXaqmYIrBFBgnRAs9MPwJjD320w1XnrM6Bxn Rz684qHmOdVow9bD1fc5eHjiUNUyFOG+VYz/fIqiFUn00XATBx1wCOIETluX0yhFpon+ zxMUrMvWOeQCYDpsRxOiCATOmLWRL/iKdeYoJFOvDiKbahkepq6+UBvPCi4gntHsORjP ueKwcB3wX6BNf3zZZ8hKNhWRHqGYfewCBMaLKHFVqZ+UPLRuLD4wg/QsR3TqP+LbNiSP aucw== X-Gm-Message-State: AOJu0Yz+vWOGHkKMTBtlJBhpB9fb0KBQ6o5k7u+HukWbBs/GjhpKxvta rqMCfx6AmtFvCCEHItbtBSzom0VejnypUPe3Jv1T1SJhjimmiWTLqSYx/hnHjJ53FkkqIBiR5Kd BhZezLNxHL9jdffoHOYUTFEaq7MYJN/YU1gZo X-Gm-Gg: ATEYQzxbEXKl7MGyHlxpLsgfWVTWpXp+M2o1DWqgGH8PuzjQa2I/qCowowogkyGoQps U5FTxNHjB3LVU1SKJcam0glOVQt3j1C74w0myxp5J5IuiBIS7Zo9CxhpJydLEqrdRpmqU20LeP2 0QN3hMHL+SjipeNEbsQnCPM6rmgaj2W3ovdpfh4A1vryj9Kf5ENAtCy3UBRy8ypA7AEW199ccCw nAYALdLT/fP7kl9fLvHih913Plv79qvuK/0gza0yPV5pWTvHvkven9rLxbowcZzFHMQVGWyYWKG QZWZ82OqRnLQBaqHcIYZ3nN9WTDUzjyL58QQjF4i X-Received: by 2002:a05:6a20:2590:b0:39c:179:4278 with SMTP id adf61e73a8af0-39c87c01ba5mr13948482637.48.1774866030200; Mon, 30 Mar 2026 03:20:30 -0700 (PDT) MIME-Version: 1.0 From: Ibrahim Shaame Date: Mon, 30 Mar 2026 13:20:14 +0300 X-Gm-Features: AQROBzACpoMeBXKcV5IjTTGauKgfnra5lBGPk1LO0Nn8gYEByjaHohU40b8nbHQ Message-ID: Subject: Adding column in a recursive query To: "pgsql-novice@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000410a57064e3b330f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000410a57064e3b330f Content-Type: text/plain; charset="UTF-8" I have a working recursive query. I want to add another column, but it gives me an error: Here is the working one: ***************************** WITH RECURSIVE x(jina, namba, nasaba_1) AS ( SELECT (((majina2.jina::text || ' '::text) || majina2.baba::text) || ' '::text) || majina2.babu::text AS jina, majina2.namba, majina2.nasaba_1, majina2.kuzaliwa, majina2.anza_mchango, majina2.mwisho_mchango FROM majina2 WHERE majina2.nasaba_1 = 0 UNION ALL SELECT ((((((x_1.jina || ' '::text) || ' - '::text) || e.jina::text) || ' '::text) || e.baba::text) || ' '::text) || e.babu::text, e.namba, e.nasaba_1, e.kuzaliwa, e.anza_mchango, e.mwisho_mchango FROM majina2 e, x x_1 WHERE e.nasaba_1 = x_1.namba ) SELECT jina, namba, nasaba_1, (length(jina) - length(replace(jina, '-'::text, ''::text))) / length('-'::text) AS depth, kuzaliwa, anza_mchango, mwisho_mchango FROM x ORDER BY jina; ************************ But when I add these lines: (((majina2.jina::text || ' '::text) || majina2.baba::text) || ' '::text) || majina2.babu::text AS jina_2, the upper part when executed separately its works: When adding this in the UNION part: (((e.jina::text || ' '::text) || e.baba::text) || ' '::text) || e.babu::text AS jina_2, I get the following error: ERROR: operator does not exist: integer = text LINE 21: WHERE e.nasaba_1 = x_1.namba ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. Any suggestion of where I am doing it wrong? Thanks in advance Ibrahim Shaame --000000000000410a57064e3b330f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I have a working recursive query. I want to add anoth= er column, but it gives me an error:=C2=A0
Here is the working on= e:
*****************************
WITH RECURSIVE x(jina,= namba, nasaba_1) AS (
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0SELECT (((majin= a2.jina::text || ' '::text) || majina2.baba::text) || ' '::= text) || majina2.babu::text AS jina,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 majina2.namba,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 majina2.= nasaba_1,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 majina2.kuzaliwa,=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 majina2.anza_mchango,
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 majina2.mwisho_mchango
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0FROM majina2
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 WHERE majina2.nasaba_1 =3D 0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 UNION ALL=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0SELECT ((((((x_1.jina || ' '::t= ext) || ' - '::text) || e.jina::text) || ' '::text) || e.ba= ba::text) || ' '::text) || e.babu::text,
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 e.namba,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = e.nasaba_1,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 e.kuzaliwa,
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 e.anza_mchango,
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 e.mwisho_mchango
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0FROM majina2 e,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 x= x_1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 WHERE e.nasaba_1 =3D x_1.namba=C2=A0 =C2=A0 =C2=A0 =C2=A0 )
=C2=A0SELECT jina,
=C2=A0 =C2=A0 namb= a,
=C2=A0 =C2=A0 nasaba_1,
=C2=A0 =C2=A0 (length(jina) - length(repla= ce(jina, '-'::text, ''::text))) / length('-'::text)= AS depth,
=C2=A0 =C2=A0 kuzaliwa,
=C2=A0 =C2=A0 anza_mchango,
=C2= =A0 =C2=A0 mwisho_mchango
=C2=A0 =C2=A0FROM x
=C2=A0 ORDER BY jina;
************************
But when I add these lines:
=C2=A0 =C2=A0(((majina2.jina::text || ' '::text) || majina2.= baba::text) || ' '::text) || majina2.babu::text AS jina_2,
the upper part when executed separately its works:=C2=A0
<= br>
When adding this in the UNION part:=C2=A0=C2=A0(((e.jina::tex= t || ' '::text) || e.baba::text) || ' '::text) || e.babu::t= ext AS jina_2,
I get the following error:

ERROR: =C2=A0operator does not exist: integer =3D text
LINE 21: =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 WHERE e.nasaba_1 =3D x_1.namba
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^
HINT: =C2=A0No operator matc= hes the given name and argument types. You might need to add explicit type = casts.


Any suggestion of where I am= doing it wrong?=C2=A0

Thanks in advance
Ibrahim Shaame
--000000000000410a57064e3b330f--