Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
Insert, update or alter column in postgres when working with to_char

What i have;

3 tables in postgres 9.4. Table 1 is the main table tables 2 and 3 contain some additional data (an update multiplier) which is quarterly (eg. Q1 2017 formatted as varchar). Table 1 has a date of transaction in date format along with a price paid column. I've added a column called 'quarters' to populate with new data which will be stored as varchar.

What i want to do;

Generate a quartely column in table 1, which i can do using

SELECT to_char(dateoftransfer, '"Q"Q YYYY') as quarters
FROM  table_1;

If i then try;

UPDATE table_1 (quarters)
SELECT to_char(dateoftransfer, '"Q"Q YYYY') as quarters
FROM  table_1;

I get the following error

ERROR:  syntax error at or near "quarters"
LINE 1: (quarters)
     ^

Should i be using COPY or INSERT INTO in place? The reason i want the column in table 1 is so that i can generate an update price column in table 1 by using a WHERE statement to find the correct multiplier. Its an inflation adjustment calculation.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think this is what you want.

UPDATE table_1 
SET quarters = to_char(dateoftransfer, '"Q"Q YYYY');
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda