0

i am trying to insert a date value in numeric datatype column of postgres table

insert into table tablename(col1) values(2017-09-25);

In the above query col1 is of type numeric.

Also can I insert some of the values using value() clause and some using the select statement? for example:

create tableA(col1 serial,col2 bigint,col3 bigint,col4 text,col5 boolean);

In the above table: 1. col1 is coming sequence 2. col2 and col3 are coming from the join of two tables i.e. tableB and tableC 3. col4 and col5 are the hard-coded value

how can i achieve this in a single query?

for insertion with the join of two tables can be achieved as follows:

insert into table(col2,col3) 
select tableB.col2,tableC.col3 
from tableB, tableC 
where tableB.id=1 and tableC.id=3;

so the output wil be like:

col1 col2 col3 col4 col5 
1     1    3 

now how to insert the values of col4 and col5 also with the values of col2 and col3?

anyone any idea?

I am not able to find it.

1
  • please divide the question to individual posts with clear data sample, error and question Commented Sep 26, 2017 at 8:58

1 Answer 1

1
insert into table(col2, col3, col4, col5) 
select tableB.col2, tableC.col3, 'some text', true
from tableB, tableC 
where tableB.id=1 and tableC.id=3;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.