Меню

Value too long in statement ошибка

Автор foghog, 2 марта 2012, 14:40

0 Пользователи и 1 гость просматривают эту тему.

Эта же проблема описывается на англоязычном форуме
http://www.oooforum.org/forum/viewtopic.phtml?t=25749&start=0&postdays=0&postorder=asc&highlight=&sid=465e237d4f7c4cc88e31c2652c2aaf9e

Создана таблица, ключ указан
12 полей, у том числе присутствуют

ID INTEGER
Текстовые VARCHAR, в том числе с различными ограничениями длины
Несколько полей NUMERIC, с разным количеств знаков после запятой
BOOLEAN
ДАТА

При вводе данных (не важно, через форму или через прямо в таблицу) выдается такая ошибка

Ошибка по всем полям.
При этом все заполнено в соответствии с ограничениями.
Ошибку выдают ВСЕ поля которые заполнены на момент перехода к новой записи.
Если заполнены все, то все и выдают..

Пример:

———-
Состояние SQL: 22001
Код ошибки: -124

Value too long in statement [INSERT INTO «Products» ( «Alc»,»Note»,»Har»,»ID») VALUES ( ?,?,?,?)]

———-

Кто-нибудь сталкивался с таким?
База создана с нуля, две таблицы из пять выдают такую же ошибку..


На англоязычном форуме такие же идиоты, как и везде.
Хоть бы кто-нибудь выложил БД с ошибкой для детального ознакомления.

PS. Это для BigAndy на форуме Инфра-ресурса, он будет чрезвычайно рад потрепаться на эту тему.


Похоже, проблема с форматами данных в конкретных полях.

Просто вместо того чтобы сказать что несовпадение в формате полей, он говорит что во всех полях недопустимые данные..

Ошибки были в таблице такие:
— число знаков 3, после запятой 4
— интеджер там где надо просто число

Странно что он вообще позволяет такие ошибки делать..
Да.. не Майкрософт :-))

Вообщем, резолвд (пока)
Но покопаться пришлось очень долго…


  • Форум поддержки пользователей LibreOffice, Apache OpenOffice

  • Главная категория

  • Base

  • VALUE TOO LONG IN STATEMENT

I know this topic has been untouched for quite a while, but, as this is exactly the problem I’m facing now, I thought I’d post a reply, just in case someone is ‘monitoring’ it. :) (The post IS LONG — I’m describing things in detail.)

OK, my specs first: XP Home Edition, Oo v. 2.4.1.

I created a new database and table from scratch (importing from Access offered no real advantage: it’s a very specific need I’m covering for an NGO), then I built the form that was to be used (only to insert new records) using the wizard. After fine-tuning data field types and needed masks, I tested creating the first record for my table… and then I got the ‘value too long in statement’ error mentioned by Timbothecat.

Coming to the forum for some help with it (no help available for such error message if I press F1), I took the time to follow Drew’s advice and go through each data field on the table, and each control on the form, and made the necessary adjustments so length property was exactly the same on both. I then tried inserting a new record. The very fact that the form control prevented me from entering bigger amounts of data than the accepted by the table should give me a break. Unfortunately, it didn’t work like that. I got the same error message, again.

Then, I attempted something: I used the wizard to create a new table on the same database, and said ‘yes’ to the option offered at the end of the process to ‘create a form based on the table’. Before even attempting to insert a new record using that form, I went on design mode and checked the lenght for each control. All ‘Text [varchar]’ data types on the table had a 50 or 250 length assigned, and ALL text boxes that were linked to such ‘Text [varchar]’ data types had ZERO length assigned (the wizard DID assign the default 0 to text boxes maximum length, at least in my experience). In such scenario, I had no problems inserting a new record to this ‘mock’ table.

I then changed lengths on the table to a 20 value, and tried inserting more than that (it was possible as I still had the no-limit-on-length controls on the form). Obviously, it failed, and the error message appeared.

One more attempt, and I changed the control accepted length to 20. As I tried entering 21 characters, a message appeared saying the text was truncated as I was trying to insert more than the amount allowed. Great — a sign that the form length control was active, and working even before flushing the data to the table.

I then changed the form length control to 21, and I got no problems entering 21 characters, but when the form tried to record the new info on the table, the ‘value too long’ message reappeared.

All of that bring me to some conclusions:
— the form processing mechanism works exactly as explained by Drew — and that’s ONE of the reasons you might get the error message;
— (unfortunately) different lengths on form controls and table data fields are NOT the only reason for such error message to appear;
— assuring you have the same length on both form controls and table data fields DO NOT guarantee your problem will be solved… :(

Something else I noticed: text fields are not the only ones causing the problem as I get a ‘value too long’ error message for ALL the fields I try to input data to, and some of them are linked to yes/no (boolean), date, and even an Image [longvarbinary] field types on my table. :!: :roll:

So… what’s left for me to check? I know I’m missing out on something but am too tired (2.08 AM) to try anything else right now. Any ideas?

Thanks in advance!

Windows XP Home Edition — Oo 2.4.1
********************************************************************
«Knowledge is a process of piling up facts; wisdom lies in their simplification.» (M. Luther King, Jr.)
OOo 2.4.X on Ms Windows XP

I created a small development database for practice. It has a table cities with columns cityname and state. The cityname in there is ‘Cincinnati’, long name right?

mytestdb=# SELECT * FROM cities;
 cityid |  cityname  | state
--------+------------+-------
 12345  | Cincinnati | Ohio
(1 row)

I am unclear as to how and why I am getting this error message upon attempting to add ‘San Francisco’.

mytestdb=# INSERT INTO cities VALUES ('San Francisco','CA');
ERROR:  value too long for type character varying(5)

Michael Green's user avatar

asked Dec 28, 2016 at 22:05

Daniel's user avatar

3

So first, what’s the difference..

SELECT x, length(x)
FROM ( VALUES
  ('Cincinnati'),
  ('San Francisco')
) AS t(x);

Here is the output

       x       | length 
---------------+--------
 Cincinnati    |     10
 San Francisco |     13

So..

  1. San Francisco is three characters longer.
  2. They’re both over 5 characters.
  3. That can’t be the problem.

And further, if Cincinnati was in a varchar(5), it’d have to get truncated.

So the problem is your cityid. It is varchar(5). you probably want that to be an int anyway — it’ll be more compact and faster. So ALTER the table and fix it.

ALTER TABLE cities
  ALTER COLUMN cityid SET DATA TYPE int
  USING cityid::int;

As a side note… maybe someday PostgreSQL will speak column names in error messages. until then at least it’s more verbose than SQL Server.

Community's user avatar

answered Dec 28, 2016 at 22:38

Evan Carroll's user avatar

Evan CarrollEvan Carroll

58.9k42 gold badges216 silver badges442 bronze badges

The root of the problem is INSERT without target column list
— which is a popular way to shoot yourself in the foot. Only use this syntax shortcut if you know exactly what you are doing.

The manual on INSERT:

The target column names can be listed in any order. If no list of
column names is given at all, the default is all the columns of the
table in their declared order; or the first N column names, if
there are only N columns supplied by the VALUES clause or
query. The values supplied by the VALUES clause or query are associated with the explicit or implicit column list left-to-right.

The cure: list target columns explicitly.

INSERT INTO cities (cityname, state)  -- target columns!
VALUES ('San Francisco','CA');

This is assuming that cityid can be NULL or has a column default.

Typically, the table should look like this:

CREATE TABLE city  -- personal advice: use singular terms for table names
   city_id  serial PRIMARY KEY
 , cityname text NOT NULL
 , state    text NOT NULL  -- REFERENCES state(state_id)
);

Ideally, you also have a table state listing all possible states and a FOREIGN KEY reference to it.

About serial:

  • Safely and cleanly rename tables that use serial primary key columns in Postgres?

Community's user avatar

answered Dec 29, 2016 at 2:03

Erwin Brandstetter's user avatar

I’m getting this error:

psql:prep6_queries.txt:2: ERROR: value too long for type character(3)

psql:prep6_queries.txt:5: ERROR: value too long for type character(3)

psql:prep6_queries.txt:8: ERROR: value too long for type character(3)

INSERT 0 1

INSERT 0 1

psql:prep6_queries.txt:27: ERROR: syntax error at or near «VALUES»
LINE 2: VALUES (‘BOR’, ‘Klingon’, NULL, NULL);

^

Here is my code:

INSERT INTO Country(code, name, continent, population)
VALUES ('Borduria', 'BOR', 'Pangaea', 1000);

INSERT INTO country(code, name, continent, population)
VALUES ('Cagliostro', 'CAG', 'Pangaea', 250);

INSERT INTO country(code, name, continent, population)
VALUES ('Qumar', 'MAR', 'Pangaea', 3380);

INSERT INTO countrylanguage(countrycode, countrylanguage, isofficial, percentage)
VALUES ('BOR', 'English', NULL, NULL);

INSERT INTO countrylanguage(countrycode, countrylanguage, isofficial, percentage)
VALUES ('BOR', 'Italian', NULL, NULL);

INSERT INTO countrylanguage(countrycode, countrylanguage, isofficial, percentag
VALUES  ('BOR', 'Klingon', NULL, NULL);

DELETE FROM country
WHERE population < 300;

UPDATE country
SET continent = 'Luna'
WHERE name = 'Borduria' and code = 'BOR';
INSERT INTO Country(code, name, continent, population)
VALUES ('Borduria', 'BOR', 'Pangaea', 1000);

I don’t know what I’m doing wrong. I don’t understand the errors it gives me. Is it because of the country code? The country code is 3 characters long. Am I using the wrong quotation marks? Any advice?

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Thanks. We have received your request and will respond promptly.

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It’s Free!

*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

«SQL: Statement Too Long» Error

«SQL: Statement Too Long» Error

(OP)

10 Apr 07 12:31

Our VB6 app uses the Visual FoxPro Driver (6.00.8167.00) to work with a .DBF database.  A recordset is created via rs1.Open «SELECT * FROM……»  We then fill an Array with the 87 recordset fields and do record processing in the Array, which results in some (not all) changes of the original Array values.  At the end of record processing the following code is executed:

For i = 0 To 86
   If rs1.Fields(i) <> PlyrArray(i) Then
      rs1.Fields(i) = PlyrArray(i)
   End If
Next i
rs1.Update

We get the «SQL: Statement Too Long» error on the rs1.Update statement.  What could be causing this error?  Thanks.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join Tek-Tips® Today!

Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.

Here’s Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More…

Register now while it’s still free!

Already a member? Close this window and log in.

Join Us             Close

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Value does not fall within the expected range ошибка
  • Valorant ошибка установки лаунчера