Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I pass this table from sql server to postgress?

Does anyone know how I can make a generated column in postgress?
This is the code in SQL server:

CREATE TABLE [dbo].[PRICE](
    [ISIN] [varchar](50) NOT NULL,
    [Nemo] [varchar](50) NOT NULL,
    [Month(t)] [int] NOT NULL,
    [Month(t-1)] [int] NOT NULL,
    [Month(t-2)] [int] NOT NULL
        )

I searched the internet and found that the way to do it in postgress is by using GENERATE ALWAYS AS but I get an error because the month column is repeated several times, that is the question that is supposed to be differentiated when doing the subtraction.

CREATE TABLE PRICE(
    ISIN varchar(50) NOT NULL,
    Nemo varchar(50) NOT NULL,
    Month int GENERATED ALWAYS AS (t) STORED,
    Month int GENERATED ALWAYS AS (t-1) STORED,
    Month int GENERATED ALWAYS AS (t-2) STORED,
)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Those aren’t generated columns, they just have non-standard names that need quoted identifiers. In SQL Server such a column needs to be enclosed in square brackets. Postgres follows the SQL standard where such names need to be enclosed in double quotes:

CREATE TABLE PRICE (
  ISIN varchar(50) NOT NULL,
  Nemo varchar(50) NOT NULL,
  "Month(t)" int NOT NULL,
  "Month(t-1)" int NOT NULL,
  "Month(t-2)" int NOT NULL
)

Example with SQL Server

Example with PostgreSQL

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading