Skip to content

SQLC generate fails for an existing field #3947

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

Open
spdeepak opened this issue Apr 28, 2025 · 0 comments
Open

SQLC generate fails for an existing field #3947

spdeepak opened this issue Apr 28, 2025 · 0 comments

Comments

@spdeepak
Copy link

I am trying to run the sqlc generate and one of the query in the file I have is as below

WITH update_namespaces AS (
    UPDATE namespaces 
    SET name       = COALESCE(sqlc.narg('name'), name),
        updated_at = COALESCE(sqlc.narg('updated_at'), updated_at),
        updated_by = COALESCE(sqlc.narg('updated_by'), updated_by)
    WHERE namespaces.id = sqlc.arg('id')
        RETURNING *
),
update_properties AS (
UPDATE namespaces_properties
SET allow_content_deletion = COALESCE(sqlc.narg('allow_content_deletion'), allow_content_deletion)
WHERE namespace_id = sqlc.arg('id')
    RETURNING *
    ),
    update_emergency_contacts AS (
UPDATE namespaces_emergency_contacts
SET email                  = COALESCE(sqlc.narg('emergency_email'), email),
    public_slack_channel    = COALESCE(sqlc.narg('public_slack_channel'), public_slack_channel),
    public_slack_channel_id = COALESCE(sqlc.narg('public_slack_channel_id'), public_slack_channel_id),
    slack_group             = COALESCE(sqlc.narg('slack_group'), slack_group)
WHERE namespace_id = sqlc.arg('id')
    RETURNING *
    ),
    delete_existing_locales AS (
DELETE FROM namespaces_locales
WHERE namespace_id = sqlc.arg('id')
    RETURNING *
    ),
    insert_new_locales AS (
INSERT INTO namespaces_locales (namespace_id, locale_id)
SELECT sqlc.arg('id'), unnest(sqlc.arg('locales')::text[])
ON CONFLICT (namespace_id, locale_id) DO NOTHING
    RETURNING *
    ),
    delete_existing_components AS (
DELETE FROM namespaces_components
WHERE namespace_id = sqlc.arg('id')
    RETURNING *
    ),
    insert_new_components AS (
INSERT INTO namespaces_components (namespace_id, component_id)
SELECT sqlc.arg('id'), unnest(sqlc.arg('components')::text[])
ON CONFLICT (namespace_id, component_id) DO NOTHING
    RETURNING *
    )
SELECT
    (SELECT COUNT(*) FROM update_namespaces) AS UpdatedNamespaces,
    (SELECT COUNT(*) FROM update_properties) AS UpdatedProperties,
    (SELECT COUNT(*) FROM update_emergency_contacts) AS UpdatedEmergencyContacts,
    (SELECT COUNT(*) FROM delete_existing_locales) AS DeletedLocales,
    (SELECT COUNT(*) FROM insert_new_locales) AS InsertedLocales,
    (SELECT COUNT(*) FROM delete_existing_components) AS DeletedComponents,
    (SELECT COUNT(*) FROM insert_new_components) AS InsertedComponents;\

It throws an error saying that the allow_content_deletion field doesn't exist, where as it does exist. Any idea why? Also if I swap the update_properties and update_emergency_contacts section the error points saying email field doesn't exist which his the first column after SET.

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