Newskooler
Newskooler

Reputation: 4245

How to add a new column in an SQL select query with a specific type?

I want to create an empty column with a specific type in a select query.

This is how I can do it without specifying the type:

Select *, Null as new_empty_colum from my_table;

In this examples, it creates it of type string.

My question is how can I specify the type of new_empty_colum and why does it make it as string when I don't specify a type?

Upvotes: 0

Views: 1415

Answers (1)

user330315
user330315

Reputation:

Untyped values default to text, if you want to force a specific type, you have to cast the null value:

select *, cast(null as numeric) as new_empty_column
from my_table

Upvotes: 2

Related Questions