I need create this query dynamically:
INSERT INTO "calle" (a, b, c, d)
SELECT l.id_localidad, v.tipovial, v.nomvial, v.geom
FROM "010010001v" AS v,
dblink('dbname=xxx port=xxxx host=xxxxx user=xxx password=xxxxx',
'SELECT id_localidad
FROM "localidadesurbanas"
WHERE cvgeo = ''010010001''')
AS l(id_localidad integer);
The only thing that changes is:
...
FROM "010010001v"
...
WHERE cvgeo = ''010010001''')
...
For:
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public'
AND tablename LIKE '01%v';
"010010001v"
"010010293v"
"010010479v"
...
I hope to be clear. And if possible tutorials to learn PL/pgSQL. Thanks.