You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATE TABLE IF NOT EXISTS fails with an insufficient_privilege exception when the user executing the statement doesn't have the privileges to create the table in the current schema, even if the table exists. I don't know whether this is a bug in Postgres (9.6), even if it seems like it should succeed.
I've rewritten the statement that creates http_sessions to work around that:
stmt := `DO $$
BEGIN
CREATE TABLE IF NOT EXISTS http_sessions (
id BIGSERIAL PRIMARY KEY,
key BYTEA,
data BYTEA,
created_on TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
modified_on TIMESTAMPTZ,
expires_on TIMESTAMPTZ);
EXCEPTION WHEN insufficient_privilege THEN
IF NOT EXISTS (SELECT FROM pg_catalog.pg_tables
WHERE schemaname = current_schema() AND tablename = 'http_sessions') THEN
RAISE;
END IF;
WHEN others THEN RAISE;
END;
$$;`
which catches that exception and ignores it only if the table already exists. A bit more poking suggests that to_regclass(current_schema() || '.http_sessions') IS NULL would also work to check existence, though I've no idea which one would be preferred.
The text was updated successfully, but these errors were encountered:
CREATE TABLE IF NOT EXISTS
fails with aninsufficient_privilege
exception when the user executing the statement doesn't have the privileges to create the table in the current schema, even if the table exists. I don't know whether this is a bug in Postgres (9.6), even if it seems like it should succeed.I've rewritten the statement that creates
http_sessions
to work around that:which catches that exception and ignores it only if the table already exists. A bit more poking suggests that
to_regclass(current_schema() || '.http_sessions') IS NULL
would also work to check existence, though I've no idea which one would be preferred.The text was updated successfully, but these errors were encountered: