Importing CSV with jsonb and array with PGAdmin4 - database

I am trying PGAdmin4 to import. Whenever I run the import it throws this error:
ERROR: invalid input syntax for type json
DETAIL: Token "size" is invalid.
CONTEXT: JSON data, line 1: {size...
COPY media, line 1, column details: "{size: 1097267, width: 2950, height: 2094, dateTime: null, latitude: null, longitude: null, cameraMo..."
Table Structure:
ID (int) name(text) details(jsonb) tags(text[])
Data:
27 Beautiful beach {"size": 1097267, "width": 2950} {amazing,asia,attraction}
PG Admin Import Settings:

I ended up creating a database archive (.tar) and restored it via PGAdmin database restore option.
It Worked.

Related

Getting Error -> SequelizeDatabaseError: Conversion failed when converting the nvarchar value 'create' to data type int

This is a weird error. To set the background: I've built a React app utilizing SQL Server some months ago. Abandoned the project and now am resurrecting it. When last visited, everything worked fine. I could enter and retrieve data from the database. Project was saved to GitHub. Now I'm revisiting it and I'm having trouble getting data into the database. I had to rebuild my MAC (2019 MBA) and the database. Here is the table structure (the SQL file to create the database same that initially created it back months ago, this is just the portion for the offending table):
CREATE TABLE budgets (
id INT IDENTITY(1, 1) PRIMARY KEY NOT NULL,
clientid INT DEFAULT NULL,
catitem varchar(100) DEFAULT NULL,
subcatitem varchar(100) DEFAULT NULL,
start_date varchar(12) DEFAULT NULL,
end_date varchar(12) DEFAULT NULL,
quantity INT DEFAULT 1,
frequency VARCHAR(10) DEFAULT NULL,
cost decimal(10,2) DEFAULT NULL,
createdAt date DEFAULT NULL,
updatedAt date DEFAULT NULL
);
Here is the API call to store the data (React, Axios, Serialize):
exports.create = (req, res) => {
// Save Budget to MSSQL database
Budgets.create({
clientid: req.body.clientid,
catitem: req.body.catitem,
subcatitem: req.body.subcatitem,
start_date: req.body.startDate,
end_date: req.body.endDate,
quantity: req.body.quantity,
frequency: req.body.frequency,
cost: req.body.cost,
}).then(budget => {
// Send created budget to budgets
res.send(budget);
}).catch(err => {
res.status(500).send("Error -> " + err);
})
};
None of the code React code has changed. Here is my Postman URL:
http://localhost:8080/api/budgets/create?clientid=2&catitem='Business Services'&subcatitem='Concierge IT'&startDate='1/1/2020'&endDate='12/312020'&quantity=1&frequency='Monthly'&cost=1000.00
The error generated from Postman:
Error -> SequelizeDatabaseError: Conversion failed when converting the nvarchar value 'create' to data type int.
Running an INSERT script in Azure Data Studio is successful. Any ideas what would be causing this error?
So figured out what was happening in Postman to generate the error. I was sending the request with a GET insetead of a POST. Now it's posting a new record to the table except that it only contains the auto-generated fields (id, createdAt, and updatedAT). The passed in values don't get posted.?

IMDB to SQLite: How to create table and insert imdb data into sqlite database?

I'm working on a project where I want the select IMDB files (The files format is in *.list) that I downloaded from here into a sqlite database. Unfortunately, I'm not able to solve this issue. I'm able to create a database but can't tabulate the table with IMDB data.
The documentation I've been following is here. So far, I created a sqlite table but it will not populate it.
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by db_file
:param db_file: database file
:return: Connection object or None
"""
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return None
def create_table(conn, create_table_sql):
""" create a table from the create_table_sql statement
:param conn: Connection object
:param create_table_sql: a CREATE TABLE statement
:return:
"""
try:
c = conn.cursor()
c.execute(create_table_sql)
except Error as e:
print(e)
def main():
database = "/Users/Erudition/Desktop/imdb_database/sqldatabase.db"
sql_create_tile_akas = """ CREATE TABLE IF NOT EXISTS title (
titleid text PRIMARY KEY,
ordering integer NOT NULL,
title text,
region text,
language text NOT NULL,
types text NOT NULL,
attributes text NOT NULL,
isOriginalTitle integer NOT NULL
); """
conn = create_connection(database)
if conn is not None:
# create projects table
create_table(conn, sql_create_tile_akas)
else:
print("Error! cannot create the database connection.")
if __name__ == '__main__':
main()
In the terminal, I enter
imdbpy2sql.py -d /Users/Erudition/Desktop/imdb_database/aka-titles.list/
-u sqlite:///sqldatabase.db'''
The output I expect is a sqlite table with all the rows filled. Instead, I get a several sqlite tables with nothing filled out.
The terminal output is:
WARNING The file will be skipped, and the contained
WARNING information will NOT be stored in the database.
WARNING Complete error: [Errno 20] Not a directory:
'/Users/Erudition/Desktop/imdb_database/aka-titles.list/complete-
cast.list.gz'
WARNING WARNING WARNING
WARNING unable to read the "/Users/Erudition/Desktop/imdb_database/aka-
titles.list/complete-crew.list.gz" file.
WARNING The file will be skipped, and the contained
WARNING information will NOT be stored in the database.
WARNING Complete error: [Errno 20] Not a directory:
'/Users/Erudition/Desktop/imdb_database/aka-titles.list/complete-
crew.list.gz'
I found the solution!
pip install imdb-sqlite
Then
imdb-sqlite
Here's the link

Apache Drill - SQL Server plugin does not 'Show Tables'

Using Apache Drill,
I successfully created new plugin : mssql
Configuration:
{
type: "jdbc",
driver: "com.microsoft.sqlserver.jdbc.SQLServerDriver",
url: "jdbc:sqlserver://99.99.99.999:1433;databaseName=ABC",
username: "abcuser",
password: "abcuser",
enabled: true
}
But when i try to query again a table I get an error:
select * from mssql.ABC.dbo.TableName
Error:
org.apache.drill.common.exceptions.UserRemoteException: VALIDATION ERROR: From line 1, column 15 to line 1, column 19: Table 'mssql.ABC.dbo.TableName' not found SQL Query null [Error Id: feba9fdb-1621-438a-9d7c-304e4252a41f on AA99-9AA9A99.xyz.abc.com:31010]
Even the below command returns no tables:
show tables;
It should be like
select * from mssql.dbo.TableName

How to Update Doc in Cloudant no sql-db

I am following Link to integrate cloudant no sql-db.
There are methods given create DB, Find all, count, search, update. Now I want to update one key value in one of my DB doc file. how Can i achieve that. Document shows like
updateDoc (name, doc)
Arguments:
name - database name
docID - document to update
but when i pass my database name and doc ID its throwing database already created can not create db. But i wanted to updated doc. So can anyone help me out.
Below is one of the doc of may table 'employee_table' for reference -
{
"_id": "0b6459f8d368db408140ddc09bb30d19",
"_rev": "1-6fe6413eef59d0b9c5ab5344dc642bb1",
"Reporting_Manager": "sdasd",
"Designation": "asdasd",
"Access_Level": 2,
"Employee_ID": 123123,
"Employee_Name": "Suhas",
"Project_Name": "asdasd",
"Password": "asda",
"Location": "asdasd",
"Project_Manager": "asdas"
}
So I want to update some values from above doc file of my table 'employee_table'. So what parameters I have to pass to update.
first of all , there is no concept named table in no sql world.
second, to update document first you need to get document based on any input field of document. you can also use Employee_ID or some other document field. then use database.get_query_result
db_name = 'Employee'
database = client.create_database(db_name,throw_on_exists=False)
EmployeeIDValue = '123123'
#here throw_on_exists=False meaning dont throw error if DB already present
def updateDoc (database, EmployeeIDValue):
results = database.get_query_result(
selector= { 'Employee_ID': {'$eq': EmployeeIDValue} }, )
for result in results:
my_doc_id = result["_id"]
my_doc = database[my_doc_id] #===> this give you your document.
'''Now you can do update'''
my_doc['Employee_Name'] = 'XYZ'
my_doc.save() ====> this command updates current document

Symfony column type text

I want a column in my database to be of type text (an unlimited amount of text).
In my schema:
bio: { type: text }
Migration file generated:
$this->changeColumn('organization', 'bio', 'text', '', array());
When I try to migrate I get the following error:
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1. Failing Query: "ALTER TABLE organization CHANGE bio bio text()"
What is the correct syntax for such a field?
Try to use "string" instead of "text"
bio: { type: string }

Resources