Subject | Metadata about views |
---|---|
Author | Łukasz Bączek |
Post date | 2014-04-06T19:51:51Z |
Hi,
How can extract information about the view?
My view :
"CREATE OR ALTER VIEW SALDO_UMOWY(
ID_UMOWY,
SALDO)
AS
SELECT faktury.id_umowy AS id_umowy, IIF((SELECT EXTRACT(YEAR FROM
umowy.data_podpisania) FROM umowy WHERE
umowy.id_umowy=faktury.id_umowy)<=2010, (SELECT
SUM(COALESCE(faktury.brutto-umowy.kwota_fn,0)) FROM faktury WHERE
faktury.id_umowy=faktury.id_umowy), (SELECT
SUM(COALESCE(faktury.netto-umowy.kwota_fn,0)) FROM faktury WHERE
faktury.id_umowy=faktury.id_umowy)) AS saldo FROM faktury, umowy"
which gives two fields:
1 ID_UMOWY - it is part of a table
2 SALDO - is here used function sum()
I have a question:
"SELECT IIF(b.rdb$field_name = f.rdb$field_name,1,0) AS primary_key,
b.rdb$field_name AS field,
IIF(POSITION('RDB$' IN c.rdb$field_name) = 0,c.rdb$field_name, CASE
WHEN (((c.rdb$field_type=14) OR (c.rdb$field_type=15)) AND
(c.rdb$field_length = 16) AND (c.rdb$character_set_id =1) ) THEN 'GUID'
WHEN (c.rdb$field_type= 261) AND (c.rdb$field_sub_type =1) THEN 'TEXT'
WHEN (c.rdb$field_type= 261) AND (c.rdb$field_sub_type <>1) THEN 'BINARY'
WHEN (((c.rdb$field_type=14)OR(c.rdb$field_type=15)) AND
c.rdb$field_length <>16 AND c.rdb$character_set_id <>1 ) THEN 'CHAR'
WHEN (c.rdb$field_type=40 OR c.rdb$field_type=41) THEN 'TEXT'
WHEN (c.rdb$field_type=11 OR c.rdb$field_type=27) THEN 'DOUBLE'
WHEN c.rdb$field_type=10 THEN 'FLOAT'
WHEN ((c.rdb$field_type=9) OR (c.rdb$field_type=16) OR
(c.rdb$field_type=45)) AND (c.rdb$field_scale < 0) THEN 'DECIMAL'
WHEN ((c.rdb$field_type=9) OR (c.rdb$field_type=16) OR
(c.rdb$field_type=45)) AND (c.rdb$field_scale >= 0) THEN 'BIGINT'
WHEN (c.rdb$field_type=8) AND (c.rdb$field_scale < 0) THEN 'DECIMAL'
WHEN (c.rdb$field_type=8) AND (c.rdb$field_scale >= 0) THEN 'INTEGER'
WHEN (c.rdb$field_type=7) AND (c.rdb$field_scale < 0) THEN 'DECIMAL'
WHEN (c.rdb$field_type=7) AND (c.rdb$field_scale >= 0) THEN 'SMALLINT'
WHEN c.rdb$field_type=12 THEN 'DATE'
WHEN c.rdb$field_type=13 THEN 'TIME'
WHEN c.rdb$field_type=35 THEN 'TIMESTAMP'
WHEN (c.rdb$field_type=37) OR (c.rdb$field_type=38) THEN 'VARCHAR'
ELSE 'UNKNOWN'
END) AS TYPE,
COALESCE(b.rdb$null_flag,0) AS notnull,
c.rdb$field_length AS LENGTH,
ABS(c.rdb$field_scale) AS scale,
a.rdb$relation_name AS table_name
FROM rdb$relations a
INNER JOIN rdb$relation_fields b ON a.rdb$relation_name =
b.rdb$relation_name
INNER JOIN rdb$fields c ON b.rdb$field_source = c.rdb$field_name
INNER JOIN rdb$types d ON c.rdb$field_type = d.rdb$type
INNER JOIN rdb$relation_constraints e ON e.rdb$relation_name =
a.rdb$relation_name
INNER JOIN rdb$index_segments f ON f.rdb$index_name = e.rdb$index_name
RIGHT JOIN extract_metadata_view EMV ON
EMV.depended_on_table=A.rdb$relation_name AND
EMV.field_name=b.rdb$field_name AND EMV.view_name = 'SALDO_UMOWY'
WHERE a.rdb$system_flag = 0 AND d.rdb$field_name = 'RDB$FIELD_TYPE' AND
e.rdb$constraint_type = 'PRIMARY KEY'
ORDER BY a.rdb$relation_name, b.rdb$field_id"
used in this query is the view:
"CREATE OR ALTER VIEW extract_metadata_view(
view_name,
field_name,
depended_on_table,
depended_on_field)
AS
SELECT d.rdb$dependent_name AS view_name,
r.rdb$field_name AS field_name,
d.rdb$depended_on_name AS depended_on_table,
d.rdb$field_name AS depended_on_field
FROM rdb$dependencies d
LEFT JOIN rdb$relation_fields r ON d.rdb$dependent_name =
r.rdb$relation_name
AND d.rdb$field_name = r.rdb$base_field
WHERE r.rdb$system_flag = 0
AND d.rdb$dependent_type = 1 --VIEW
ORDER BY r.rdb$field_position"
The query returns information about the fields that are in the view
but returns only the fields that are in the table,
when the field is a function that is not returned as a change to be
returned or fields that are a function of how SALDO
Regards
How can extract information about the view?
My view :
"CREATE OR ALTER VIEW SALDO_UMOWY(
ID_UMOWY,
SALDO)
AS
SELECT faktury.id_umowy AS id_umowy, IIF((SELECT EXTRACT(YEAR FROM
umowy.data_podpisania) FROM umowy WHERE
umowy.id_umowy=faktury.id_umowy)<=2010, (SELECT
SUM(COALESCE(faktury.brutto-umowy.kwota_fn,0)) FROM faktury WHERE
faktury.id_umowy=faktury.id_umowy), (SELECT
SUM(COALESCE(faktury.netto-umowy.kwota_fn,0)) FROM faktury WHERE
faktury.id_umowy=faktury.id_umowy)) AS saldo FROM faktury, umowy"
which gives two fields:
1 ID_UMOWY - it is part of a table
2 SALDO - is here used function sum()
I have a question:
"SELECT IIF(b.rdb$field_name = f.rdb$field_name,1,0) AS primary_key,
b.rdb$field_name AS field,
IIF(POSITION('RDB$' IN c.rdb$field_name) = 0,c.rdb$field_name, CASE
WHEN (((c.rdb$field_type=14) OR (c.rdb$field_type=15)) AND
(c.rdb$field_length = 16) AND (c.rdb$character_set_id =1) ) THEN 'GUID'
WHEN (c.rdb$field_type= 261) AND (c.rdb$field_sub_type =1) THEN 'TEXT'
WHEN (c.rdb$field_type= 261) AND (c.rdb$field_sub_type <>1) THEN 'BINARY'
WHEN (((c.rdb$field_type=14)OR(c.rdb$field_type=15)) AND
c.rdb$field_length <>16 AND c.rdb$character_set_id <>1 ) THEN 'CHAR'
WHEN (c.rdb$field_type=40 OR c.rdb$field_type=41) THEN 'TEXT'
WHEN (c.rdb$field_type=11 OR c.rdb$field_type=27) THEN 'DOUBLE'
WHEN c.rdb$field_type=10 THEN 'FLOAT'
WHEN ((c.rdb$field_type=9) OR (c.rdb$field_type=16) OR
(c.rdb$field_type=45)) AND (c.rdb$field_scale < 0) THEN 'DECIMAL'
WHEN ((c.rdb$field_type=9) OR (c.rdb$field_type=16) OR
(c.rdb$field_type=45)) AND (c.rdb$field_scale >= 0) THEN 'BIGINT'
WHEN (c.rdb$field_type=8) AND (c.rdb$field_scale < 0) THEN 'DECIMAL'
WHEN (c.rdb$field_type=8) AND (c.rdb$field_scale >= 0) THEN 'INTEGER'
WHEN (c.rdb$field_type=7) AND (c.rdb$field_scale < 0) THEN 'DECIMAL'
WHEN (c.rdb$field_type=7) AND (c.rdb$field_scale >= 0) THEN 'SMALLINT'
WHEN c.rdb$field_type=12 THEN 'DATE'
WHEN c.rdb$field_type=13 THEN 'TIME'
WHEN c.rdb$field_type=35 THEN 'TIMESTAMP'
WHEN (c.rdb$field_type=37) OR (c.rdb$field_type=38) THEN 'VARCHAR'
ELSE 'UNKNOWN'
END) AS TYPE,
COALESCE(b.rdb$null_flag,0) AS notnull,
c.rdb$field_length AS LENGTH,
ABS(c.rdb$field_scale) AS scale,
a.rdb$relation_name AS table_name
FROM rdb$relations a
INNER JOIN rdb$relation_fields b ON a.rdb$relation_name =
b.rdb$relation_name
INNER JOIN rdb$fields c ON b.rdb$field_source = c.rdb$field_name
INNER JOIN rdb$types d ON c.rdb$field_type = d.rdb$type
INNER JOIN rdb$relation_constraints e ON e.rdb$relation_name =
a.rdb$relation_name
INNER JOIN rdb$index_segments f ON f.rdb$index_name = e.rdb$index_name
RIGHT JOIN extract_metadata_view EMV ON
EMV.depended_on_table=A.rdb$relation_name AND
EMV.field_name=b.rdb$field_name AND EMV.view_name = 'SALDO_UMOWY'
WHERE a.rdb$system_flag = 0 AND d.rdb$field_name = 'RDB$FIELD_TYPE' AND
e.rdb$constraint_type = 'PRIMARY KEY'
ORDER BY a.rdb$relation_name, b.rdb$field_id"
used in this query is the view:
"CREATE OR ALTER VIEW extract_metadata_view(
view_name,
field_name,
depended_on_table,
depended_on_field)
AS
SELECT d.rdb$dependent_name AS view_name,
r.rdb$field_name AS field_name,
d.rdb$depended_on_name AS depended_on_table,
d.rdb$field_name AS depended_on_field
FROM rdb$dependencies d
LEFT JOIN rdb$relation_fields r ON d.rdb$dependent_name =
r.rdb$relation_name
AND d.rdb$field_name = r.rdb$base_field
WHERE r.rdb$system_flag = 0
AND d.rdb$dependent_type = 1 --VIEW
ORDER BY r.rdb$field_position"
The query returns information about the fields that are in the view
but returns only the fields that are in the table,
when the field is a function that is not returned as a change to be
returned or fields that are a function of how SALDO
Regards