From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | Victor Blomqvist <vb(at)viblo(dot)se> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Drop or alter column under load give ERROR #42804 structure of query does not match function result type: |
Date: | 2015-10-12 12:29:44 |
Message-ID: | 20151012122944.GU30738@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
On 2015-10-09 14:32:44 +0800, Victor Blomqvist wrote:
> Typically I have user defined functions for all operations, and my table
> and functions follow this pattern:
>
> CREATE TABLE users (
> id integer PRIMARY KEY,
> name varchar NOT NULL,
> to_be_removed integer NOT NULL
> );
>
> CREATE FUNCTION select_users(id_ integer) RETURNS SETOF users AS
> $$
> BEGIN
> RETURN QUERY SELECT * FROM users WHERE id = id_;
> END;
> $$ LANGUAGE plpgsql;
>
> Then the actual queries are run by our application as
>
> SELECT id, name FROM select_users(18);
>
> As you can see the column to_be_removed is not selected. Then to remove the
> column I use:
>
> ALTER TABLE users DROP COLUMN to_be_removed;
>
> However, while the system is under load sometimes (more frequently and
> persistent the more load the system is experiencing) I get errors like
> these:
>
> ERROR #42804 structure of query does not match function result type:
> Number of returned columns (2) does not match expected column count (3).
My guess is that the problem here is that table level locking prevents
modification of the "users" type when the table is used, but there's no
locking preventing the columns to be dropped while the function is
used. So what happens is that 1) the function is parsed & planned 2)
DROP COLUMN is executed 3) the contained statement is executed 4) a
mismatch between the contained statement and the function definition is
detected.
Greetings,
Andres Freund
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2015-10-12 13:42:52 | Re: Drop or alter column under load give ERROR #42804 structure of query does not match function result type: |
Previous Message | Andres Freund | 2015-10-12 12:25:22 | Re: Drop or alter column under load give ERROR #42804 structure of query does not match function result type: |