1
I have two tables, the Table Impressoras
is where is stored the data of the equipment, as model, patrimony, etc. And I have the table Impressora Local
where the location of the printer is stored, the client where it is currently allocated.
My table Impressoras
has a column codigoempresa
where when the printer and registered is placed the initial company where it goes, and in this table Impressora Local
is stored a history of where the printer passed, for this reason in this table Impressora Local
the company (company code) is always updated, but in the table Impressoras
nay.
I was able to solve this issue of keeping this data updated in the table Impressora
also creating a Funtion in the database that whenever a record is changed or added to the table Impressora Local
the data (company code) is automatically updated. This works normally.
But the first time, I will have to update this data on the arm, for this reason I tried to do an Update command as follows:
UPDATE public.impressoras
SET codigoempresa=(select codigoempresa from public.impressoralocal)
WHERE public.impressoras.codigo = (select codigoimpressora from public.impressoralocal);
But the following error is returned to me:
ERROR: more than one row returned by a subquery used as an expression
********** Error **********
ERROR: more than one row returned by a subquery used as an expression
SQL state: 21000
My question is, is it possible to update this table like this Impressoras
, or I will be required to update line by line
Observing: This bank is a legacy for this reason I’m having to adopt such a measure
Table Printers:
Table Printer Loca:
put the table structure please, and what query you run on "first time"
– Rovann Linhalis
@Rovannlinhalis as so first time?
– R.Santos
you who said, "But the first time, I will have to update this data on the arm," that would be in INSERT ? which code you run ?
– Rovann Linhalis
Oh yes, it’s just that today’s table
Impressoras
is with thecodigoempresa
outdated I will have to do the first Update command in hand, today I am changing so:UPDATE public.impressoras
 SET codigoempresa = 20 where
 codigoimpressora in (4,5,6)
. But there are many printers so I would like to know if there is a more effective way– R.Santos
I understand, if you can put the structure of the tables that helps a lot
– Rovann Linhalis