You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by Gyula Fóra <gy...@gmail.com> on 2024/01/11 07:57:44 UTC

Optional fields during SQL insert

Hi All!

Is it possible to insert into a table without specifying all columns of the
target table?
In other words can we use the default / NULL values of the table when not
specified somehow?

For example:
Query schema: [a: STRING]
Sink schema:  [a: STRING, b: STRING]

I would like to be able to simply insert with column a and get null values
for b.
For a simple table like the above it doesn't make much of a practical
difference but if you have very large tables with complex fields and a lot
of optional columns this can be very useful.

Thank you!
Gyula

Re: Re: Optional fields during SQL insert

Posted by Gyula Fóra <gy...@gmail.com>.
This worked perfectly Xuyang, nice :)

Thanks!

On Thu, Jan 11, 2024 at 12:52 PM Xuyang <xy...@163.com> wrote:

> Hi, Gyula.
> If you want flink to fill the unspecified column with NULL, you can try
> the following sql like :
> ```
> INSERT INTO Sink(a) SELECT a from Source
> ```
>
>
> --
>     Best!
>     Xuyang
>
>
> 在 2024-01-11 16:10:47,"Giannis Polyzos" <ip...@gmail.com> 写道:
>
> Hi Gyula,
> to the best of my knowledge, this is not feasible and you will have to do
> something like *CAST(NULL AS STRING)* to insert null values manually.
>
> Best,
> Giannis
>
> On Thu, Jan 11, 2024 at 9:58 AM Gyula Fóra <gy...@gmail.com> wrote:
>
>> Hi All!
>>
>> Is it possible to insert into a table without specifying all columns of
>> the target table?
>> In other words can we use the default / NULL values of the table when not
>> specified somehow?
>>
>> For example:
>> Query schema: [a: STRING]
>> Sink schema:  [a: STRING, b: STRING]
>>
>> I would like to be able to simply insert with column a and get null
>> values for b.
>> For a simple table like the above it doesn't make much of a practical
>> difference but if you have very large tables with complex fields and a lot
>> of optional columns this can be very useful.
>>
>> Thank you!
>> Gyula
>>
>

Re:Re: Optional fields during SQL insert

Posted by Xuyang <xy...@163.com>.
Hi, Gyula.
If you want flink to fill the unspecified column with NULL, you can try the following sql like :
```
INSERT INTO Sink(a) SELECT a from Source
```





--

    Best!
    Xuyang




在 2024-01-11 16:10:47,"Giannis Polyzos" <ip...@gmail.com> 写道:

Hi Gyula,
to the best of my knowledge, this is not feasible and you will have to do something like CAST(NULL AS STRING) to insert null values manually.
 

Best,
Giannis


On Thu, Jan 11, 2024 at 9:58 AM Gyula Fóra <gy...@gmail.com> wrote:

Hi All!


Is it possible to insert into a table without specifying all columns of the target table?
In other words can we use the default / NULL values of the table when not specified somehow?


For example:
Query schema: [a: STRING]
Sink schema:  [a: STRING, b: STRING]



I would like to be able to simply insert with column a and get null values for b. 
For a simple table like the above it doesn't make much of a practical difference but if you have very large tables with complex fields and a lot of optional columns this can be very useful.


Thank you!
Gyula

Re: Optional fields during SQL insert

Posted by Giannis Polyzos <ip...@gmail.com>.
Hi Gyula,
to the best of my knowledge, this is not feasible and you will have to do
something like *CAST(NULL AS STRING)* to insert null values manually.

Best,
Giannis

On Thu, Jan 11, 2024 at 9:58 AM Gyula Fóra <gy...@gmail.com> wrote:

> Hi All!
>
> Is it possible to insert into a table without specifying all columns of
> the target table?
> In other words can we use the default / NULL values of the table when not
> specified somehow?
>
> For example:
> Query schema: [a: STRING]
> Sink schema:  [a: STRING, b: STRING]
>
> I would like to be able to simply insert with column a and get null values
> for b.
> For a simple table like the above it doesn't make much of a practical
> difference but if you have very large tables with complex fields and a lot
> of optional columns this can be very useful.
>
> Thank you!
> Gyula
>