Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate table specification - error with large tables #13

Open
int-red opened this issue Jun 30, 2020 · 0 comments
Open

Generate table specification - error with large tables #13

int-red opened this issue Jun 30, 2020 · 0 comments

Comments

@int-red
Copy link

int-red commented Jun 30, 2020

When generating table specification directly using the T-SQL query by querying system views you provided an error occurs when there are tables with many columns. Error:
"STRING_AGG aggregation result exceeded the limit of 8000 bytes. Use LOB types to avoid result truncation."

The solution, which I found here: https://andyhogg.wordpress.com/2019/01/09/a-couple-of-notes-on-the-string_agg-function/
, is to cast to NVARCHAR(MAX).

the modified T-SQL query is:
select CONCAT('new TableSpec("',schema_name(t.schema_id), '","', t.name, '")') + string_agg(CONCAT('.AddColumn("', cast(c.name as NVARCHAR(MAX)), '", "', cast(tp.name as NVARCHAR(MAX)), '", isKeyColumn:', IIF(ix.is_primary_key = 1, 'true', 'false'), '))'),'') from sys.tables t join sys.columns c on t.object_id = c.object_id join sys.types tp on c.system_type_id = tp.system_type_id left join sys.index_columns ic on c.column_id = ic.column_id and c.object_id = ic.object_id left join sys.indexes ix on ic.index_id = ix.index_id and ic.object_id = ix.object_id --where t.name in ('','','') --> specify target tables if needed. group by t.schema_id, t.name

JocaPC added a commit that referenced this issue Jun 30, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Fix recommended in #13
JocaPC added a commit that referenced this issue Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant