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

sql-runner fails on IF EXISTS statements #38

Open
gabrielcrowdtilt opened this issue Oct 7, 2015 · 19 comments
Open

sql-runner fails on IF EXISTS statements #38

gabrielcrowdtilt opened this issue Oct 7, 2015 · 19 comments
Assignees
Labels
Milestone

Comments

@gabrielcrowdtilt
Copy link

For example, web-incremental step 00-preparation:
https://github.com/snowplow/snowplow/blob/master/5-data-modeling/sql-runner/redshift/sql/web-incremental/00-preparation/00-preparation.sql#L25

Gives this output

2015/10/07 04:12:30 EXECUTING 00-preparation (in step 00-preparation @ snowplow): /opt/snowplow/sql_runner/analytics/sql/web-incremental/00-preparation/00-preparation.sql
2015/10/07 04:12:30 FAILURE: 00-preparation (step 00-preparation @ target snowplow), ERROR: ERROR #3F000 schema "snplw_temp" does not exist: 
2015/10/07 04:12:30 
TARGET INITIALIZATION FAILURES:
QUERY FAILURES:
* Query 00-preparation /opt/snowplow/sql_runner/analytics/sql/web-incremental/00-preparation/00-preparation.sql (in step 00-preparation @ target snowplow), ERROR:
  - ERROR #3F000 schema "snplw_temp" does not exist: 

Can sql-runner be made to handle this edge case. It would also allow one to create playbooks for all initial schema and table setup.

@alexanderdean
Copy link
Member

/cc @bogaert

@alexanderdean
Copy link
Member

Using psql:

db00002=# drop schema if exists foobar cascade;
INFO:  Schema "foobar" does not exist and will be skipped
DROP SCHEMA

It has to be a bug in the underlying Golang Postgres driver. We could try to upgrade to v3 of that driver and see if the problem goes away; if not then I think we have to raise a bug with the driver maintainers.

@alexanderdean alexanderdean added this to the Version 0.3.0 milestone Oct 7, 2015
@alexanderdean alexanderdean self-assigned this Oct 7, 2015
@jbeemster
Copy link
Member

Hey @alexanderdean not sure where to go with this ticket as we have this command in our integration-test with no issues.

https://github.com/snowplow/sql-runner/blob/master/integration-tests/postgres-sql/good/1.sql#L3

@alexanderdean
Copy link
Member

I have seen this issue when running Snowplow playbooks - this may be a Postgres vs Redshift issue?

@jbeemster
Copy link
Member

Quite possible! I will try running this against a Redshift target to re-create.

@alexanderdean
Copy link
Member

Thanks Josh!

@jbeemster
Copy link
Member

This fails against a Redshift Target with v2 and v3.

@jbeemster
Copy link
Member

Further on this it is not just the DROP SCHEMA IF EXISTS command but also just a CREATE SCHEMA command. Seems to have issues working with schemas in general.

@alexanderdean
Copy link
Member

Can you reproduce with psql, or is this only a SQL Runner issue?

@jbeemster
Copy link
Member

Can confirm that this is only an issue with SQL Runner, running the same playbook from CLI using psql works exactly as it should. Should we raise an issue with them about this?

@alexanderdean
Copy link
Member

That's super weird. It must be a bug in the Golang PG v2 driver. Can we try upgrading to the v3, see if the problem goes away?

@jbeemster
Copy link
Member

Did that already sadly.

@alexanderdean
Copy link
Member

Let's create a separate ticket to upgrade to v3 of the PG driver in this release anyway...

@jbeemster
Copy link
Member

SQL Runner fails when running both of the following commands:

DROP SCHEMA IF EXISTS any_schema_here CASCADE;

-- OR

CREATE SCHEMA any_schema_here;

I tried running both of these lines against a fresh Redshift cluster and they both failed with the: ERROR #3F000 schema "any_schema_here" does not exist:

From psql to the same cluster everything runs as expected.

@andrioni
Copy link
Contributor

We also faced the same issue here, but IIRC doing the schema manipulation queries as the only query in a separate step worked, at least on Redshift, but I might be misremembering.

@iaingray
Copy link

iaingray commented Jan 7, 2016

I've just run into this bug too on 0.4.0.

  • ERROR #3F000 schema "staging" does not exist.

When running DROP SCHEMA IF EXISTS followed by CREATE SCHEMA then commands which depend on the schema.

I can confirm that moving the schema DROP/CREATE into its own step is an effective workaround.

The scripts work ok when run through Navicat, so it's a sql-runner specific thing.

@esquire900
Copy link

In case anybody keeps hitting this problem like happend with us: the only way that seemed to solve this was to move

CREATE SCHEMA IF NOT EXISTS snplw_temp;

from the top of 00-preparation to the end of 08-track-queries.

@alexanderdean
Copy link
Member

Thanks for sharing Simon!

@alexanderdean
Copy link
Member

Pushing back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants