How to fix Encoding error utf-8 - PostgreSQL - sql

I am following instructions online to create a database in pgAdmin4. I have successfully imported a csv file and created a table. However, I cannot select anything from the table.
My code is:
SELECT * FROM transfers;
Error message is: 'utf-8' codec can't decode byte 0xc3 in position 0: unexpected end of data
Running 'show server_encoding' gives "UTF8" in the output.
Running 'show client_encoding gives "UNICODE" in the output.

Maybe you saved an excel file as csv and imported to postgre, if so, open excel, create a blank csv file and copy/paste your excel data to there and save. Delete your previous postgre table and import newly created csv file again.

Related

Export data from Oracle SQL Developer to Excel .xlsx

I have a small project where data from Oracle SQL Developer needs to be exported to Excel (using commands rather than tools in SLQ Developer), then create a graph.
Using "spool" I can export to csv fine (but cant make a graph in csv) but when I try to export to xlsx it corrupts the whole excel sheet saying
"Excel cannot open the file "ExcelFile.xlsx" because the file format or file extention
is not valid. Verify that the file has not been corrupted and that the
file extension mathces the format of the file."
Here is the code I used in SQL Developer.
spool FileLocation\ExcelFile.xlsm
SELECT * FROM Table;
spool off;
Is there any way I can stop the data from becoming corrupted or is there another way to export data to a .xlsx file?
Nooooooo.
set sqlformat csv
spool c:\file.sql
select * from table;
spool off;
then open the file in excel.
OR
Run your query interactively.
Right click on the grid, Export > XLSX. Open the file.
Spool only writes the query output to the file, it doesn't look at the file extension and figure out HOW to write the output at that point.
So you either have to code it yourself via the query, or use one of the format outputs we support
SET SQLFORMAT
CSV
JSON
DELIMITED
XML
HTML
INSERT
LOADER
Use 'help set sqlformat' for help.
Hi sql developer from what I know for exporting is using sqlplus(code is same) so perhabs there are other ways but this one should be good enough
I would try changing first line to look like this:
spool ExcelFile.xls
Probably you also need to turn on
SET MARKUP HTML ON
http://www.orahow.com/2015/09/spool-sqlplus-output-to-excel-format.html
Anyway there is workaround - you can just generate .CSV file and then open it in excel and save as .xlsx file
I was also facing the same problem then applied below code and it exported successfully..
import xlsxwriter
from xlsxwriter import Workbook
import cx_Oracle
import datetime
from datetime import date
dsn_tns = cx_Oracle.makedsn('HOST', 'PORTNO', sid='BGRDB')
db = cx_Oracle.connect(user=r'username', password='password', dsn=dsn_tns)
cursor = db.cursor()
workbook = xlsxwriter.Workbook('C:/Path/outfile.xlsx')
sheet = workbook.add_worksheet()
cursor.execute("select * from TABLENAME")
for r, row in enumerate(cursor.fetchall()):
for c, col in enumerate(row):
sheet.write(r, c, col)
workbook.close()
cursor.close()

Error in *.xlsm file when writing strings using xlsm

I am using openpyxl (2.3.2) to write out an xlsm file. I can write the numeric values correctly but the string values are corrupting the xlsm file. In the code example below, the xlsm file is corrupted but the xlsx file works well
When I open the xlsm file , I get a error
we found a problem with some content in samp2.xlsm
On continuing, I see only the numeric values are written and not the string values. This does not happen with the xlsx file.
This is a strange problem
PS The "Samp.xlsm" and "Sample.xlsx" Files are new files saved with these names. They do not have any content.
Appreciate any suggestions/feedback

Import .xlsx to oracle sql developer error

I am exporting a .xlsx file with 1,000,000 rows to sql developer using the 'Import Data' function. However, I get the error:
Error during handleEvent on action 'Import Data... ' (id=998).
None of the attached controllers handled the action. - oracle.ide.controller.IdeAction$ControllerDelegatingController#6eb6ea5e[oracle.dbt ools.raptor.controls.sqldialog.ObjectACtionController]
Can someone please help? Thanks!
Try using .xls file instead of .xlsx file. It should work fine.

OleDB ' Unspecified error' VB

I am using oledb to get data from .txt file and i have encountered error.
Dim oleDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\CompName\C$\Path;ExtendedProperties="Text;HDR=Yes;FMT=Fixed""
where CompName and Path are real values
I get Unspecified error in adapter fill
Using connection As New OleDbConnection(oleDb)
Using command As New OleDbCommand(sql, connection)
Using adapter As New OleDbDataAdapter(command)
adapter.Fill(s)
End Using
End Using
End Using
Return s
End Function
anyone tried geting data across intranet from different computer using oledb?
To use the OleDb Text Driver with a text file formatted with fixed length columns you need to have a SCHEMA.INI file in the same folder where the text files are located.
The SCHEMA.INI allows to define various property for the text file like Format, Field Names, Widths and Types, character sets and some conversion rules.
From MSDN
When the Text driver is used, the format of the text file is
determined by using a schema information file. The schema information
file is always named Schema.ini and always kept in the same directory
as the text data source. The schema information file provides the
IISAM with information about the general format of the file, the
column name and data type information, and several other data
characteristics. A Schema.ini file is always required for accessing
fixed-length data. You should use a Schema.ini file when your text
table contains DateTime, Currency, or Decimal data, or any time that
you want more control over the handling of the data in the table.
More details about the SCHEMA.INI file could be found on this MSDN page

BCP - Exported files (docx, xlsx & pptx) are corrupted

I am using the below bcp command to export the binary files from the filestream db and all other files are seems to be exported fine (i.e. txt, pdf, rtf, image files & etc) except docx, xlsx & pptx files. I am able to export these files (i.e. docx, xlsx & pptx) but I am getting a warning/error message when opening those files and then it opens the file properly.
BCP "SELECT content FROM [dbo].[Contents] WHERE ID=1" queryout "C:\Temp\" -T -S (local) -f C:\Temp\files.fmt
I am getting the below message when opening docx, xlsx & pptx files:
XLSX - Excel found unreadable content and Do you want to recover the contents of this document?
DOCX - The file test.docx cannot be opened bcos there are problems with the content and then Excel found unreadable content and Do you want to recover the contents of this document?
Also, I have this in my files.fmt file:
10.0
1
1 SQLBINARY 0 0 "\t" 1 content ""
Any help will be much appreciated.
I am not 100% sure if your problem was the same as what I have had but in my case, I found that the problem was actually in the writing part, not in the reading part. For example, my original writing code was like this:
Dim FILE_CONTENT(len) As Byte
File.InputStream.Read(FILE_CONTENT, 0, len)
SaveFileToDatabase(FILE_NAME, CONTENT_TYPE, FILE_CONTENT)
When I changed the first line as the following :
Dim FILE_CONTENT(0 To len - 1) As Byte
the reading error disappeared. I just forgot that VB actually allocates N+1 bytes (O to N) by default when you dimension it without specifying the lower bound. See similar situation described here: Uploaded Docx Files are getting corrupted . hope that helps.