2

I want to achieve the following behaviour NULL AS (Oracle database):

CREATE OR REPLACE VIEW cuentaahorroview AS
    SELECT IBAN as CCC, Interes, Ultimo_devengo
        FROM De_Ahorro
    UNION
    SELECT CCC, TIPOINTERES as Interes, null as Ultimo_devengo
        FROM CUENTAAHORRO@SCHEMA2BD2;

in a PostgreSQL database:

CREATE VIEW EditorialView AS
    SELECT * 
        FROM dblink('hostaddr=127.0.0.1 port=5432 dbname=bdp3e1 user=postgres password=1234', 'SELECT * FROM Editorial') 
        AS t1(nombre VARCHAR(100), CIF integer, ubicacion VARCHAR(50))
    UNION
    SELECT *
        FROM dblink('hostaddr=127.0.0.1 port=5432 dbname=bdp3e2 user=postgres password=1234', 'SELECT * FROM Editorial')
        AS t2(nombre VARCHAR(100), CIF integer, NULL);

so as the union to work. How can I do it?

This is the error I'm getting:

psql:PR3_Vistas.sql:10: ERROR:  syntax error at or near "NULL"
LINE 8:   AS t2(nombre VARCHAR(100), CIF integer, NULL);
6
  • Did you try running it? what happened? Commented May 10, 2019 at 8:36
  • @KaushikNayak question edited Commented May 10, 2019 at 8:39
  • Why are you trying to use "NULL" as a type? Commented May 10, 2019 at 8:39
  • I just want to make both sides of the union have the same number of attributes, as I did in Oracle Commented May 10, 2019 at 8:40
  • 1
    Replace select *with select field1, field2, ... and use NULL as fieldx in second part of union. select * is always bad in unions - you can't be sure that both tables have identical structure. Commented May 10, 2019 at 8:43

1 Answer 1

1

Replace select * with select field1, field2, ... and use NULL as fieldx in second part of union. select * is always bad in unions - you can't be sure that both tables have identical structure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.