Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
Executing a Function on all Columns in a Select Query

I have defined this function, to trim trailing whitespace:

create or replace function trim_trailing_whitespace(value text) returns text as $$ begin return regexp_replace(value, '\s+$', ''); end; $$ language plpgsql immutable;

It works correctly when used in queries like this one:

select trim_trailing_whitespace(SomeColumn), count(*) from MyTable group by SomeColumn;

However, it fails when I try to utilize it with a wildcard, like so:

select trim_trailing_whitespace(*) from MyTable;

LINE 1: select trim_trailing_whitespace(*) from MyTable;

HINT: No function matches the given name and argument types. You might need to add explicit type casts.

How can I execute a function on all columns within a select query? In my case, I want to trim the trailing whitespace off of each column when performing the selection.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

If possible, define a second VARIADIC version of your function. Iterate the args with a FOREACH and execute your current function on each argument.

Good example here: https://www.depesz.com/2008/07/31/waiting-for-84-variadic-functions/

over 4 years ago · Santiago Trujillo Denunciar

0

You can use dynamic sql or expand * yourself manually.

SELECT FORMAT(
  'SELECT %s FROM %I.%I.%I;',
  string_agg(
    FORMAT(
      'trim_trailing_whitespace(%I)',
      column_name
    ),
    ', '
  )
  , table_catalog, table_schema, table_name
)
FROM information_schema.columns
WHERE table_catalog = current_catalog
  AND table_schema = current_schema
  AND table_name = 'MyTable'
GROUP BY table_catalog, table_schema, table_name;
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda