I normally use the desc table option.
First lets create the table with some example data:
create or replace temporary table ColumnTypesTest (
id int identity(1,1) primary key,
userName varchar(30),
insert_DT datetime default CAST(CONVERT_TIMEZONE('UTC', CAST(CURRENT_TIMESTAMP() AS TIMESTAMP_TZ(9))) AS TIMESTAMP_NTZ(9)) not null,
nextDayAfterInsert datetime as dateadd(dd,1,insert_DT)
);
insert into ColumnTypesTest (userName) values
('John'),
('Cris'),
('Anne');
select * from ColumnTypesTest;
ID |
USERNAME |
INSERT_DT |
NEXTDAYAFTERINSERT |
1 |
John |
2021-10-04 19:11:21.069 |
2021-10-05 19:11:21.069 |
2 |
Cris |
2021-10-04 19:11:21.069 |
2021-10-05 19:11:21.069 |
3 |
Anne |
2021-10-04 19:11:21.069 |
2021-10-05 19:11:21.069 |
Now the answer to your question
Using the 'desc table <table_name>;' you will get a column named kind which will tell you if it is virtual or not, also separately there is the default with NULL if it has no default value.
name |
type |
kind |
null? |
default |
primary key |
unique key |
check |
expression |
comment |
policy name |
ID |
NUMBER(38,0) |
COLUMN |
N |
IDENTITY START 1 INCREMENT 1 |
Y |
N |
|
|
|
|
USERNAME |
VARCHAR(30) |
COLUMN |
Y |
|
N |
N |
|
|
|
|
INSERT_DT |
TIMESTAMP_NTZ(9) |
COLUMN |
N |
CAST(CONVERT_TIMEZONE('UTC', CAST(CURRENT_TIMESTAMP() AS TIMESTAMP_TZ(9))) AS TIMESTAMP_NTZ(9)) |
N |
N |
|
|
|
|
NEXTDAYAFTERINSERT |
TIMESTAMP_NTZ(9) |
VIRTUAL |
Y |
|
N |
N |
|
DATE_ADDDAYSTOTIMESTAMP(1, INSERT_DT) |
|
|
A/
With 'desc table <table_name>' you get meta data of the table with a column named kind, which will say VIRTUAL or COLUMN. In case it is VIRTUAL, then in the column expression you get how that column is calculated.
This is used in Stored Procedures, and saved in an array of arrays with javascript, from there the next query in the stored procedure is created dynamically. A while loop is used to go through the resultSet and push each row intho the array of arrays. You can then use javascript filter to just get the virtual columns. This is part of the advantage of having a mix of javascript and SQL in Snowflake Stored Procedures.
Here the documentation which doesn't say much.