Buscar un valor específico en todas las tablas de la Base de Datos, con PostgreSQL:
CREATE OR REPLACE FUNCTION search_columns(
needle text,
haystack_tables name[] default '{}',
haystack_schema name[] default '{}'
)
RETURNS table(schemaname text, tablename text, columnname text, rowctid text)
AS $$
begin
FOR schemaname,tablename,columnname IN
SELECT c.table_schema,c.table_name,c.column_name
FROM information_schema.columns c
JOIN information_schema.tables t ON
(t.table_name=c.table_name AND t.table_schema=c.table_schema)
WHERE (c.table_name=ANY(haystack_tables) OR haystack_tables='{}')
AND (c.table_schema=ANY(haystack_schema) OR haystack_schema='{}')
AND t.table_type='BASE TABLE'
LOOP
EXECUTE format('SELECT ctid FROM %I.%I WHERE cast(%I as text)=%L',
schemaname,
tablename,
columnname,
needle
) INTO rowctid;
IF rowctid is not null THEN
RETURN NEXT;l;
END IF;
END LOOP;
END;
$$ language plpgsql;
Luego ejecutar la consulta:
SELECT * FROM search_columns('value1');
Suscribirse a:
Comentarios (Atom)
Visita nuestras apps, Youtube y tiendas online.
César OpenSource Expert, Videos. Youtube channel: https://youtube.com/@rockcesar85 Visita nuestra tienda online: https://shop.latin-chai...
-
Pi, Pi Network and the Pi logo are trademarks of the Pi Community Company. Our webpage, LatinChain Platform: https://latin-chain.com Latin...
-
DONATE HERE, OPTIONAL (DONA AQUÍ, OPCIONAL): https://dev-rockcesar.blogspot.com/2025/03/donations-to-latinchain.html?m=1 Documento (Españo...
-
OpenSource Expert 🇻🇪 Sígueme en mis Redes Sociales (Follow me in my Social Networks): Redes Sociales: Youtube 📺: https://youtube.com/...