Skip to content

SQLC generate fails for an existing field #3947

Open
@spdeepak

Description

@spdeepak

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions