从PostgreSQL 数据库中把数据导出来,并保存成csv格式的文件的时候报错。开始是运行没有问题,后来数据多了一些就报错了。一度怀疑人生。

0x01 运行环境

Cent OS 6.4 x64
psql (PostgreSQL) 9.4.15

0x02 问题

解决 ERROR: invalid input syntax for type bytea

报错大义是不可用的bytea类型输入语法。

select cast (request as bytea) from nginx_log where id = 5567;
ERROR:  invalid input syntax for type bytea
时间: 0.201s

这个报错很无语,因为没有指出哪里有问题。syntax一度让我认为是语法有问题,但是又不像以往的语法错误会指明错误位置。
看下bytea的官方定义【
传送门】:

8.4.1. bytea Hex Format
The “hex” format encodes binary data as 2 hexadecimal digits per byte, most significant nibble first. The entire string is preceded by the sequence \x (to distinguish it from the escape format). In some contexts, the initial backslash may need to be escaped by doubling it (see Section 4.1.2.1). For input, the hexadecimal digits can be either upper or lower case, and whitespace is permitted between digit pairs (but not within a digit pair nor in the starting \x sequence). The hex format is compatible with a wide range of external applications and protocols, and it tends to be faster to convert than the escape format, so its use is preferred.
Example:
SELECT ‘\xDEADBEEF’;

bytea是二进制数据的16进制表现格式,这中格式的字符串以’\x’为前缀(以区分其转义格式)。在一些特殊的上下文中,原始的反斜杠可能需要通过翻倍来转义。日,发现google翻译比我翻译的好,还是用谷歌的吧。

bytea格式
"hex"格式将二进制数据编码为每字节2个十六进制数字,最高有效位在前。 整个字符串以序列\ x开头(以将其与转义格式区分开)。 在某些情况下,可能需要通过将其加倍来转义初始反斜杠(请参见第4.1.2.1节)。对于输入,十六进制数字可以是大写或小写,并且在数字对之间允许空格(但在数字对之内或在开始的\ x序列中均不允许)。十六进制格式与广泛的外部应用程序和协议兼容,并且其转换速度通常比转义格式更快,因此首选使用。

也就是说如果原始数据中有反斜杆\就需要转义变成\\才行。看下我的数据

select request from nginx_log where id = 5567;
|request|
|/news.php?pid=..\..\..\..\..\..\..\..\windows\win.ini|

你妹的果然有问题

增加对反斜杠的转移,搞定

select cast (replace(request, '\', '\\') as bytea) from nginx_log where id = 5567;

0x03 问题小结

request字段是varchar类型的,转换成bytea可能会出现’'需要转义的问题

0x04 参考文献

http://www.postgresql.org/docs/9.5/interactive/datatype-binary.html

0x00前言0x01问题解决 ERROR: invalid input syntax for type bytea报错大义是不可用的bytea类型输入语法。select cast (request as bytea) from nginx_log where id = 5567;ERROR: invalid input syntax for type bytea时间: 0.20...
文章目录1. 问题描述2. 解决方案 1. 问题描述 在使用PostgreSQL数据库时遇到错误消息“invalid input syntax”,表明我们正在处理的是一个常见错误。完整的错误信息通常是下面这样: ERROR: invalid input syntax for type numeric: "c" at character 32 2. 解决方案 当用户试图插入与列类型不匹配的值时,会发生此错误。如果问题不是由于输入错误而引起的,则可能是需要开发人员解决的应用程序端错误。 OPC server and FIX driver for Siemens S7/S5 communication via Ethernet TCP/IP, MPI or Profibus Version 7.20 Date: 26.02.2007 Version history ================================================================================================================== Build 224 New Functions: Solved problems: - The setup program created a wrong e-doc link in Windows start menu. Now the proper link to S7A.CHM will be installed - From the S7A power tool it wasn't possible to open the online help file. Now it can be opened and also the context-sensitive help works properly. - When the signal conditioning function "S&M" was used for a byte value, the driver wrote wrong values to the PLC. Build 223 : New Functions: - The number of supported NetLinks has been increased from 4 to 64 - Communication error messages will be now displayed in the alarm history of iFIX. This helps to detect, trace and solve communication issues. - Support for MATRIX licence key added. This key does not require a special key driver. It simply needs a PC and a windows version which supports USB ports. - When using the driver in conjunction with NetLink adapter, the licensing now can take place by a license code in the NetLink. In this case a separate licence key (dongle) is not needed. Note: If the connection to the NetLink is disturbed, the driver starts in demo mode, because it can't read out the licence code. If afterwards the connection to the Netlink can be established, the driver automatically changes from demo mode to the licenced mode as long as the demo time has not yet expired. - Support for S7-200 with CP 243-1 was added. Solved problems: - Passing of invalid OPC Item IDs caused a memory leak of the driver's global memory. After the global memory was exhausted, the driver crashed. - Writing of string values failed when using hardware options NULLTERM or SPACEFILL - Wrong OPC timestamp occured when driver was running in NIO Simulation Mode - The driver could crash when the driver was stopped (either by hand or when the demo time was expired) and in the same moment the NetLink connection was disturbed. - Improvements on the seamless switching between primary and backup devices and vice versa. - The passing of invalid OPC Item IDs caused a memory leak in the driver's global memory. After the global memory was exhausted, the driver crashed. - The writing of strings failed when using the hardware options NULLTERM or SPACEFILL Build 222 : New Functions: - The driver can now be registered as a service with the local system account as the log-on account. For more information see the document "S7A_as_Service.PDF" on the installation CD . - The driver now switches "seamless" between primary and backup device and vice versa. Solved problems: - The field "Default Gateway" has been added to the NetLink's configuration property page - The string write from the OPC Server sometimes failed . This bug has been fixed - After driver uninstall, not all of the S7A-related registry entries were deleted. Now the registry will be completely cleaned from S7A registry entries after uninstall. - The Netlink module generated trace messages to debug window. These trace outputs has been removed. Build 221 : New Functions: - The information field "Runtime Mode" has been added to the system statistic display. This shows whether the driver is running in the demo mode or in the licenced mode (with a valid key). - New control tag: "!RuntimeMode:S7A". A digital (i.e. DI) or analog (i.e. AI) block with the I/O address "!RuntimeMode:S7A" delivers the value 0 (in the F_CV property), when the driver is running in the demo mode, or the value 1, when the driver has found a valid key, and therefore is licenced. This function is also available via the OPC server interface. The same item-ID address format has to be used as with the tag-I/O address, thus "!RuntimeMode:S7A" - The information field "Device in use" has been added to the device statistic display. This shows which device (primary or backup-device) is currently active. This state can also be requested via the "!switch" control tag. A digital (i.e. DI) or analog (i.e. AI) block with the I/O address "!switch:<DeviceName> delivers the value 0, when the primary device is active and the value 1 when the backup device is active. For the place holder <DeviceName> in the I/O address the logical name of the driver device, which is requested, must be entered . Example: "!switch:D11" delivers the state of the driver device with the name "D11". This function is also available via the OPC server interface. The same address format has to be used for the tag-I/O address as for the item-ID, thus "!switch:<DeviceName>" - At the channel parameter dialog for the communicatiomn way "S7 TCP/IP" and "MPI/PB CIF", the combo box "Conn.Type" has been added, which now enables the selection of the connection types "PG", "OP" and "other". Until now, a PG connection was used. - In the device dialog of the communication way "MPI/PB CIF", the input fields "Rack:" and "slot no. of CPU" have been added. This extension now allows the connection to "external" Profibus- CPs (CP 342/443-5 or 343/443-5). The Profibus station address of the Profibus CP is stated in the MPI/PB address field. The rack and slot number of the S7-CPU must be stated in the corresponding fields. Please make sure that slot number of the CPU is entered and not of the Profibus-CP!! - The driver now supports the different date and time data types of the S7 PLC. See Topic "Hardware Options for OPC String and TX-Blocks to support S7 date and time data types" in the S7A online help for detailed information. Build 220 : Solved problems: - The own address of CIF50 MPI/PB communication way was limited to 31. Now the limit is 126. - Bug-fix in PG-PC Interface (CP5611) communication way. Device could be disabled from polling, after CP5611 sent a specific sequence of communication errors. Build 219 : Solved problems: Improvements and new functions: - New Parameter "Max Gap (Bytes)" on Setup parameter property page "Advanced". This parameter defines the maximum address gap between an existing and a new block at which the driver automatically appends the new block to the existing. If the address gap is greater, then the driver creates a new data block. This functionality is active, when the data block auto create option is set on. - New Radio Button selection "Show Window" on Setup parameter property page "Advanced" The driver automatically opens its window which shows trace log messages useful for trouble shooting, when the "Yes" Radio button is on. - New HTML Help Build 218 : Solved problems: - Problems with datablocks which have a length between 180 and 200 bytes. - Unsufficient exception handling in S7AMemory.Dll caused blocking of driver and all other clients (WSACTASK, Workspace, etc.) which reads data from the driver. - Error in MIX Read function could cause blocking of data blocks Build 217 : Solved problems: - In configurations with data blocks which have a primary rate of zero (as fast as possible), it sometimes happened that write requests were "stuck" in the write queue. - Sporadic locks of data blocks after the driver was switched from the primary device to the backup device Improvements and new functions: - Improved error and timeout handling on communication faults. The reply timeout on the device configuration page can no longer be configured. Instead it will be derived from the TCP/IP timeout value, configured on the channel configuration page. The value (in seconds) of reply timeout always is 1 second higher than the TCP/IP timeout. This ensures, that the logical read/write request (time-limited by reply timeout value) will not be cancelled (by timeout) before the physical request (time-limited by TCP/IP timeout value) is finished regulary or through the timeout. - The NIO Simulation mode has been expanded. If it is set "ON" the polling of data blocks will be disabled, due to which no communication errors will arise, as long as a PLC hardware is not connected to the driver. In this mode the iFix data base blocks reads the value of zero or respectively, the last value written to the driver`s output data area. - "!SyncPoll" and "!SyncSend" have been added to allow e.g. an EDA application to read/write a data block synchronously Build 216 : Solved problems: (06.06.05) - Reset of statistic counters failed Build 215 : Solved problems: (31.05.05) - An error in the OLE interface methods ReadValue ()and WriteValue() was corrected. These functions can now be used for example,within the Excel program, to access data block values. - Datablocks stopped polling after an 'unknown error' was returned by CP5611 Build 214 : Solved problems: - Syncronous reads/writes from concurrent OPC clients now work properly New function: - Performance has been improved, especially in configuration with a lot of short data blocks. - system, channel, driver and data block static display has been extended Build 213 : Solved problems: - No reconnect after the MPI/Profibus connection between CP5611 and the PLC was aborted. - S7ADRV.EXE could crash on Multi Processor Systems or Systems with Hyperthreading when error messages (e.g. "Unable to connect to MPI station") were put to driver's log window from different threads concurrently. Build 212 : Solved problems: - The AGLink error code -1268 (Unknown error message of the PLC) caused a blocking of the device. Now the device will be closed and re-opened to recover the error. - under very seldom conditions a AGLink error caused a crash of S7ADRV.EXE Build 211 : Solved problems: - Setup of TCP/IP parameters failed with error -510. Problem has been solved. - Problems in configurations with more than 8 devices within a channel have been solved - Import of CSV file from S7A Version 7.16 failed - Failed to read the AG State - Configuration of a backup IP address caused a driver crash when it tried to switch from primary to backup device Build 210 : New functions: - Communication way MPI/Profibus using Siemens CPs (CP5611, 5613) added - Communication way MPI/Profibus using Hilscher CIF50 PB added - Communication to "old" S5 series via TCP/IP added - The old Sentinel Keys will not supported any longer - Check Box "Disable comm alarming" in datablock configuration allows to suppress the COMM alarms of Tags which addresses a driver datablock which is in communication error state. - Now the OPC server is OPC DA 2.05 complient Build 210 : Solved problems: - Under Windows XP the driver crashed when the network cable was not connected to ethernet card and the driver started. - A communication error on a single device caused comm errors on all other devices of the channel Build 201 : Solved problems: - CSV Import/export works now even for the new communication ways. Build 200 : Solved problems: - Handle leakage when using asynchron read mode of OPC server. This problem was fixed by migration to OPC server toolkit version 7.20 New functions: - The driver now supports additional communication ways (serial adapter, NetLink adapter and Siemens CPs (eg. CP5611). It's no longer a pure TCP/IP driver but a general driver for Siemens S7 which allows to connect via TCP/IP, MPI bus or Profibus using different interface hardware (CPs). Build 128 : Solved problems: - In big configurations with a lot of data blocks when a data block has been written it took too long until this data block was read back. Thus between the write and the read the clients (OPC or FIX) read the old data. Now after a write the driver reads the data block priorized. Build 127 : Solved problems: - The addressing range for PLC's input area and output area has been extended from 0..255 bytes to 0..4095 bytes. Build 126 : Solved problems: - Errors in manual and automatic block write functions has been fixed Build 125 : Solved problems: - Very fast consecutive analog writes to the same data block caused a crash of the S7ADRV.EXE process. This problem has been solved. Build 124 : Solved problems: - Different communication problems has been solved. - Design of message passing to driver window has changed to prevent the driver dead locks which occored under a very seldom conditions. Build 123 : Solved problems: - Changing of the IP-Address while the driver was running had no effect. This problem has been solved. Build 122 : New functions: - Now the devices within a channel processing in parallel mode - Added "Bytes per Second" to device and channel statistics - Logging of read/write requests/responses into a log file is now configurable for individual data blocks. File logging can basically be switched on/off at register page "advanced" in power tool's setup screen. - This version is already prepared to support the S7T loadable database block which will allow to work with the S7 TIME and TIME_OF_DAY data types in iFIX database. - Shared memory management has been changed to fix problems with large configurations and multi processor systems. Solved problems: - In previous versions the S7 rack number had no effect. Now it will be mapped into the right bit positions of the "called TSAP" field when opening the ISO connection within the TCP connection. - An error in output simulations mode was fixed. - An error in auto creation of data blocks was fixed. Build 121 : Solved problems: - When the slot and rack number in the device setings has been changed, the new values wasn't used when the connection has been re-established. Now the change of these parameters take place immediately. Fixed wrong display of Transmitted and Received counters of mission control's driver statistics Build 120 : Solved problems: - The OPC Server now supports read/write of Control-Tags (eg. !Send or !PollRate). Address syntax is equal to Tag I/O Address within FIX-Database. - Driver doesn't work when a channel with 8 devices was configured Build 119 : Solved problems: - Timeout value of channel template was not stored, thus it had no effect when a new channel was added. - IP-Address of device template was not stored, thus it had no effect when a new device was added. - To avoid duplicate Connection Numbers in Driver Device config, now these Connection Numbers are assigned automatically. The "Connection No" Field in Powertool's device configuration dialog is no longer enabled for input but for displaying the assigned Connection Number. - The driver devices are now limited to 8 per channel. - When running S7A driver on W2K without hardlock key (Sentinel or HASP) the Power Tool displayed an exception message box and the driver didn't start in demo mode. This problem has been solved. Build 118 : New function: - Additionaly to the Rainbow Sentinel Key the driver now supports new Aladdin HASP Key. It detects either Sentinel or HASP Key. Solved problems: - The OPC Server now supports String addresses Build 117 : Solved problems: - Now the Input Data Area of S7 can be read. That was not possible in build version 115 and 116. - The I/O address in data base builder now accepts inputs of adresses without blank between data area identifier and adress index (e.g. D11:Q1.7 or D11:I10.0). - Under a certain condidtion the S7ADrv process runs into a deadlock situation This problem has been solved. Build 116 : Solved problems: - Now the switching between primary and backup device can be configured and used. If the communication to the primary device fails, the driver automatically switches to the device configured as backup device. If the connection to the backup device fails, it switches back to the primary device. The switching even can be done by "hand" using a DI Block with I/O address "!switch:<Device name>. A F_CV value of 0 means primary device is active, F_CV value 1 means backup device is active. To change the active device just assign the corresponding value to blocks F_CV property. Build 115 : Solved problems: New functions: - To make troubleshooting easier, the driver now allowes to log messages to a log file. To enable file logging, set the following registry key value to 1: "HKLM\Software\Intellution\Drivers\S7A\DriverDefaults\WriteLogToFile" By default this value is set to 0 which disables the file logging. The log file is named S7ADrv.log and located in the drivers default config file path. All messages dispatched to the driver server window will be logged in the file as well. Caution: The log file will "not" be deleted and re-created when driver starts. It's in the users responsibility to watch the size of the log file. If you enable the dispatching of debug level 1 to 3 messages, the log file can become a huge size in a short time!! Build 114 : Solved problems: - If SAC writes faster to the driver's image table than the driver can write to the PLC, after a while the write queue filled up to 100%. This version of the driver no longer queues write requests to PLC addresses which already in the queue, but uses the already queued request by just replacing the old write value by the new value. - In configurations with more than 1 channel, the driver sometimes crashed since This problem has been solved. - The Send and Receive counts in mission control was swapped. New functions: - Driver now runs with dongle RN-4BDNBH-B (S7A) and RN-4CKEBH-B (S7A+S7B) Build 113 : Solved problems: - Error in S7AMemory.dll caused problem in applications with very large configurations (where the shared memory "S7A_InputArea" exceeded 64k). The data type information stored in the Input Area was overwritten to WORD. Thus the SAC Task interpreted the block values always as an integer no matter what data type was set for the data block in power tool. New functions: - none Build 112 : Solved problems: - CSV File import now works fine - When choosed S7M 1.x compatible address syntax, the data type combo box was been set to a data type other that saved before. New functions: - The S7-TIME format now is supported. Use a TX-blocks and the data type identifier 'T' in the Tag's I/O address to address a double word which contains a value in S7-TIME format (e.g. D11.DB100.DBT 10). Write is also possible. Build 111 : Solved problems: - Sometimes the CPU load raised to 100% when writing values. - Read/write of the last byte of a data block failed. - Block write in manaul or auto mode failed - In data block statistics sreen sometimes "stats error windows" occured because some error codes could not be found in AGLink_Error.txt file. New functions: - none Build 110 : Solved problems: - none New functions: - Added hardware options NULLTERM and SPACEFILL to control string write. Build 109 : Solved problems: - Sometimes driver hangs after communication failed. Occured when a lot of data blocks with a very short poll time has been configured and processed. New functions: - none
1:首先,解决function definition is not allow here function definition is not allow here=函数定义在此不被允许,说明函数定义格式有问题, 解决方法: 1:看函数有没有漏打了一个大括号(“{”或“}”)——百度大流, 2:看报错函数里面的引用函数或者报错函数上面的函数有没有漏打或者打错大括号,可使用注释排除法和括号检验法。
一、问题描述 在执行查询操作时,报了这个错误,通过分析,不是sql语句语法错误,如果是sql语法错误,就会报哪一行有问题,这个一看就是查询PostgreSQL数据类型搞错了,一个不是bigint类型的数据,数据库中保存的值为 1.0 .查询的时候让其作为bigint类型导致的。sql示例: select( ext ->> 'weekly_outp...
今天遇到了一个狗血的Bug,一行没有错误的代码,但是”编译器总是出现:error C2018:未知字符“0x60”。 这个错误很大程度是由于VS2008默认的字体引起的,因为在出错行的下几行我多敲了一个“·”。就是Esc键下面的字符,这个字符在界面基本被无视,我还一度把这个点当成了屏幕上的小灰点。 所以,如果出现这个问题,多寻找上下文的字符错误。
### 回答1: "invalid input syntax for type bigint" 的意思是输入的数据格式不符合 bigint 类型的要求。可能是输入的数据包含了非数字字符,或者超出了 bigint 类型的取值范围。需要检查输入数据的格式和范围,确保符合 bigint 类型的要求。 ### 回答2: 在PostgreSQL数据库中,当输入数据超出了 bigint 数据类型的范围或格式时,就会出现“invalid input syntax for type bigint”的错误消息。 bigint数据类型是一种非常大的整数类型,可以存储范围从 -9223372036854775808 到 9223372036854775807 的整数,它非常适合存储大量的数据、计算大量的统计数据等。 但是,当在输入 bigint 类型数据时,需要注意以下几点: 1. 数据类型必须是 bigint,否则会出现上述错误。 2. 输入的数据必须在 bigint 数据类型的有效范围内,否则会超出范围并出现上述错误。 3. 字符串格式必须正确,并且不包含除数字、符号和空格之外的任何字符。 例如,当您输入一个很大的数字或者一个非数字字符串时,就会出现“invalid input syntax for type bigint”的错误消息。 为了避免这种错误发生,您应该输入正确的数据类型和数据格式。如果您无法确定数据类型和格式,则可以参考PostgreSQL的文档和示例代码,或者咨询专业的数据库管理员或开发人员来获取帮助和建议。 ### 回答3: "invalid input syntax for type bigint"是一个PostgreSQL数据库错误消息,通常在向bigint类型字段插入非法文本格式值时出现。 bigint是PostgreSQL中的一种数字数据类型,表示范围从-2^63到2^63-1的整数,因此只能插入整数值。如果使用非整数文本值尝试向bigint字段插入数据,就会导致该错误消息的出现。 当向bigint字段中插入非法文本格式值时,通常可以采用以下解决方法: 1. 检查输入值是否为整数:确保插入的文本格式值转换为整数类型。 2. 确定视图或查询是否正确:通过查看视图或查询,确定是在正确的地方尝试插入值。 3. 使用默认值:如果插入NULL 值没有反应,则需要使用默认值。 4. 查看数据库的限制:查看数据库管理系统的设置是否对输入值进行了限制。 总之,"invalid input syntax for type bigint"错误消息的出现通常是由于尝试向bigint字段插入非整数类型的文本格式值所致。可以通过确保插入的值为整数类型,查看视图或查询是否正确,使用默认值或查看数据库的限制等方法来解决此问题。
错误:UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode的解决方案 35750
错误:ORA-28547:connection to server failed, probable Oracle Net admin error的解决方案 qq_44675019: 直接删除sangfor导致断网的解决方案 miraitowa876: 牛!谢谢5555 Mac M1使用Docker报错 Failed to get D-Bus connection: No such file or directory的解决方案 南若森.: 大佬,orbstack这个问题晓得怎么解决吗 Adobe Reader历史版本安装包下载 lanrenhui: 为啥我打不开