From: | brian <brian(at)zijn-digital(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: spooky refusal to insert [SOLVED] |
Date: | 2007-01-01 21:47:37 |
Message-ID: | 45998179.4060400@zijn-digital.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
brian wrote:
> postgresql 8.1, fedora core 4
>
> I'm trying to update a database with a few new tables and insert some
> data. However, psql is refusing to insert some of the data, leading to
> errors when trying to refer to the sequence in the next insert (to a
> cross table).
>
Sure, less than ten minutes since i sent out my plea, i figured it out
for myself. For the curious:
>
> -- snip --
> DROP TABLE funding_type CASCADE;
> CREATE TABLE funding_type (
> id SERIAL PRIMARY KEY,
> name VARCHAR(16) NOT NULL
> );
>
> INSERT INTO funding_type (name) VALUES ('Grant');
> SELECT set_id('Grant ', CAST(currval('funding_type_id_seq') AS INT));
> INSERT INTO funding_type (name) VALUES ('Award');
> SELECT set_id('Award', CAST(currval('funding_type_id_seq') AS INT));
> INSERT INTO funding_type (name) VALUES ('Residency');
> SELECT set_id('Residency ', CAST(currval('funding_type_id_seq') AS INT));
> INSERT INTO funding_type (name) VALUES ('Special');
> SELECT set_id('Special ', CAST(currval('funding_type_id_seq') AS INT));
> INSERT INTO funding_type (name) VALUES ('Other');
> SELECT set_id('Other ', CAST(currval('funding_type_id_seq') AS INT));
>
Note the extra spaces after the variable names i'm using:
set_id('Grant ', ...
Because psql was not writing the errors to the file, i was relying on
what i saw in my terminal. The very last insert into arts_funder was
followed by 10 subsequent inserts into arts_funder_discipline. I'd
missed the very first error:
psql:funders.sql:1171: ERROR: null value in column "funding_type_id"
violates not-null constraint
Which is the error on insert into arts_funder. The construct
CAST(get_id('Grant') AS INT) was returning NULL because of the
whitespace, above.
I'm still confused as to why errors are not written to the output file
(\o out.txt). There must be some way to capture these, aside from a
quickly scrolling terminal window.
brian
From | Date | Subject | |
---|---|---|---|
Next Message | novnov | 2007-01-01 23:25:11 | Re: Installing support for python on windows |
Previous Message | Ken Winter | 2007-01-01 21:45:52 | How to convert "money" columns to "numeric"? |