ETLMCPData Conveyance Works
Log in Start free
Guides

Why a column named <name>_text appeared next to a numeric column

A new <column>_text field means text reached a number column of your table. Why etlmcp adds it, how to find the parked values and how to fix it.

A column such as extra.leads_text or roas_text shows up when a value that is not a number reaches a column your table already holds as a number. etlmcp cannot change the type of a column once it exists, so it writes an empty value (NULL) into the number column and keeps the original text in a new text column with the same name plus _text. The usual cause is a rule change in the pipeline, such as a new constant or a rename, that now puts words where numbers used to be. Nothing is lost, but your BI tool sees one more field, and totals over the number column miss the parked rows.

Why the type cannot follow the data

A column's type is set on the day the destination creates it, and it stays. etlmcp decides it from where the values come from, not from a sample of them:

  • the common metrics (impressions, clicks, cost, conversions, conversion_value, ctr, cpc, cpm and cpa), the extras a connector catalogues and what a group rule adds up are numbers;
  • constants, derived values and anything else are text.

In PostgreSQL a number column is created as double precision. When etlmcp loads into a table that already exists, it treats any column of type double precision, real, numeric, integer or bigint as a number column, whatever made it. Which delivered columns are numeric and which are text lists how each rule changes a column's type before the table exists.

What happens to each row

For every non-metric number column, etlmcp checks each incoming value:

Incoming value Number column gets <column>_text gets
a number, or empty the value empty
text that spells a number, such as "3" or "0.75" that number empty
any other text, such as "pending" empty the original text

The sibling column is only made when at least one value in the delivery does not fit. etlmcp adds it to your table as text, or reuses one of that name that is already text. It cannot park the text, and so drops it, when the rows already carry a column with that name, when your table has the name with another type, when the name would be longer than PostgreSQL allows for a column name, or when the database login may not alter the table.

The common metrics are never moved this way. A cost or clicks column never gets a _text sibling.

Large IDs stay text from the start

A double cannot hold every very large whole number exactly, and PostgreSQL's numeric types page describes double precision as inexact, with at least 15 digits of precision. So if a column that would be numeric holds a whole number too large for a double to keep exactly when the table is first made, etlmcp creates it as text instead. The same happens if any value in that first delivery is not a number at all. A long ID keeps every digit, and no _text sibling is needed. If you see a catalogued extra arrive as text, check its first delivery for very large values or text before you look for a rule.

Find the columns and the parked values

To list every sibling column in a table, ask the catalogue:

SELECT column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'public'
  AND table_name = 'ad_performance'
  AND column_name LIKE '%\_text'
ORDER BY column_name;

Then count what was parked per day, to see when it started. Extra columns keep their dots in PostgreSQL, so put their names in double quotes:

SELECT date, count(*) AS parked_rows, min("extra.leads_text") AS example
FROM public.ad_performance
WHERE "extra.leads_text" IS NOT NULL
GROUP BY date
ORDER BY date;

The first date with parked rows usually matches the day the pipeline's rules changed.

Fix it

  • The column should stay numeric. Change the rule that writes text into it: give the constant or the renamed column a different name. The next run writes numbers again for its date range. Rows from earlier runs keep their parked text until you backfill those dates.
  • You want to read both in one field. Build a view over the table. PostgreSQL's COALESCE returns its first argument that is not null, so it can show the number where there is one and the text elsewhere:
CREATE OR REPLACE VIEW public.ad_performance_report AS
SELECT date, campaign_name,
       "extra.leads" AS leads,
       COALESCE("extra.leads"::text, "extra.leads_text") AS leads_label
FROM public.ad_performance;

If your BI tool already reads a view, note that PostgreSQL's CREATE OR REPLACE VIEW lets you add columns only at the end, and the existing ones must keep their names, order and types.

  • The column should now be text. For an extra. column, you can drop it from the table with ALTER TABLE. On the next load etlmcp adds it back with the type that delivery calls for, which is text when text is in it. Dropping removes the old values for every date, so backfill the dates you need. A common column that is missing is refused, not re-added, so use a new table name for those instead: etlmcp creates the new table on its next load.

After any of these, refresh the field list in your BI tool so it picks up the change. See the PostgreSQL destination for how the table is created and loaded, and transforms for the rules that set a column's type.

Where this applies

The sibling column belongs to typed database tables, and among the destinations you can use today that means PostgreSQL. CSV files carry no column types, so a text value simply sits in its cell there.

Related

Sources

  1. 8.1. Numeric Types — www.postgresql.org, checked
  2. 9.19. Conditional Expressions — www.postgresql.org, checked
  3. CREATE VIEW — www.postgresql.org, checked