Skip to main content
Question

How to INSERT INTO with SELECT and default values

  • Jul 13, 2021 4:32 PM UTC
  • 3 replies
  • 21 views

markus_zhang

Hi friends, can't find related material online.

Question, I have a table with column a, b and c, a is a sequence and b is defaulted to be say 0.
I take column c from a SELECT clause.

How do I do this kind of things?

I tried:

INSERT INTO table
SELECT
default,
default,
c
FROM whatever

This doesn't work. Any idea? Thanks!

3 replies

markus_zhang
  • Author
  • New Participant
  • Jul 13, 2021 4:40 PM UTC

It seems that I cannot SELECT default. If I can't do that how am I supposed to INSERT into any table with less columns?


marcothesane
Forum|alt.badge.img+1
  • Participating Frequently
  • Jul 13, 2021 4:42 PM UTC

Just specify the columns into which you actually want to insert something:

INSERT INTO the_table(
 c
)
SELECT
  c
FROM whatever;

markus_zhang
  • Author
  • New Participant
  • Jul 13, 2021 4:45 PM UTC

@marcothesane said:
Just specify the columns into which you actually want to insert something:

INSERT INTO the_table(
 c
)
SELECT
  c
FROM whatever;

Thanks, it works! Perfect~~