21
SQL Server does not store UTF-8 under any circumstances. You get either UTF-16 Little Endian (LE) via NVARCHAR (including NCHAR and NTEXT, but don't ever use NTEXT) and XML, or some 8-bit encoding, based on a Code Page, via VARCHAR (including CHAR and TEXT, but don't ever use TEXT).
The problem here is that your code is mistranslating that 0x82 character, ...
answered Aug 4 '17 at 15:12
Solomon Rutzky
61.7k66 gold badges126126 silver badges253253 bronze badges
17
The "Cannot assign requested address" part in the error message comes from the kernel TCP stack. When encountered intermittently, this typically means that the space of available sockets is exhausted because of too much sockets in wait state (TIME_WAIT, or less probably FIN_WAIT_1 or FIN_WAIT_2)
The range of socket ports can be output by cat /proc/sys/net/...
14
It's to do with Python's object model - there's always a way to get a reference to objects that could be unsafe. See the rexec module documentation and the restricted execution chapter of the docs for some info on the problems, as well as:
https://www.researchgate.net/publication/228612669_Controlling_access_to_resources_within_the_python_interpreter
http://...
answered Mar 16 '16 at 6:39
Craig Ringer
47.9k33 gold badges123123 silver badges160160 bronze badges
13
You can use the EXCLUDED keyword to access the values passed to INSERT. No need to pass them twice:
insert_sql = '''
INSERT INTO {t} (id,col1, col2, col3)
VALUES (%s, %s, NULLIF(%s, 'nan'), NULLIF(%s, 'nan'))
ON CONFLICT (id)
DO UPDATE SET
(col1, col2, col3)
= (EXCLUDED.col1, EXCLUDED.col2, EXCLUDED.col3) ;
...
answered Mar 20 '17 at 8:27
ypercubeᵀᴹ
88.6k1212 gold badges170170 silver badges261261 bronze badges
12
Don't make your user transaction wait for the (hopefully!) successful completion of the Python script. Your entire transaction sits there and waits for this external process to run, try to send mail, etc. I doubt the e-mail really has to go out that instant - especially given you can't control any delays it has as it gets routed to the recipient's inbox ...
answered Dec 13 '13 at 19:36
Aaron Bertrand
170k2424 gold badges358358 silver badges566566 bronze badges
10
I find these multiple closings with age=0 worrying
No, this whole log looks fine and tends to show that pooling is working.
These entries with age=0 being tagged as LOG C, they concern communication between a client and pgBouncer. age=0 just means that the client used the connection for less than 1 second, which is consistent with the dates with ...
10
with PGBouncer, you'd probably want to just stick with NullPool. In that case you may be able to share a single Engine across subprocesses since no socket connections will be carried over the subprocess boundary. But you can't share anything referring to a Connection object, like a Session with an active transaction, over this boundary. You definitely ...
10
You can reverse the sort direction to get the minimum instead of the maximum value:
# Sort by myfield (ascending value) and return first document
collection.find_one(sort=[("myfield", 1)])["myfield"]
This example assumes that:
myfield is a numeric value (so the sort order makes sense to determine a minimum or maximum)
myfield exists in the matching ...
10
There are two typical ways to express this.
With LIKE infix search:
SELECT title FROM snippets WHERE description LIKE '%evil%';
or with position:
SELECT title FROM snippets WHERE position('evil' in description) > 0;
Note that neither are indexable by default. Search for "infix search index" for more info on that, and look into pg_trgm if you need it.
answered Oct 10 '15 at 11:15
Craig Ringer
47.9k33 gold badges123123 silver badges160160 bronze badges
10
I performed the same steps and ran into the same problem. I found that the problem was resolved by removing the ~/.pgadmin directory (created during installation) and then re-running "python pgAdmin4.py"
9
Yes, it is possible to work with multiple databases at the same time but you're looking in the wrong place. psycopg2 is just a library that simplifies accessing and manipulating data coming out of PostgreSQL but it doesn't go far beyond what you can do with psql. What you're looking to do you can solve on the database level by using Foreign Data Wrappers.
...
9
psycopg2 is a wrapper around libpq, written in C, to expose a Python DB-API compatible API to Python programs. It implements Python objects in C that call libpq functions. It has a thin Python module wrapper around it to load it and provide some of the interface functionality that's easier to write in pure Python.
Anything that implements the DB-API to ...
answered Aug 23 '15 at 23:55
Craig Ringer
47.9k33 gold badges123123 silver badges160160 bronze badges
7
This is covered in the developer FAQ, some relevant excerpts:
MongoDB stores all field names in every document. For most documents,
this represents a small fraction of the space used by a document;
however, for small documents the field names may represent a
proportionally large amount of space
And, just a note on indexes:
Shorter field names do ...
7
sudo apt autoremove pgadmin4
works for ubuntu version 18.04
6
You might be able to use the service broker, though that is probably overkill, as you state.
Alternately, if you don't want to install/manage an extra service for this one need, you could use xp_cmdshell or a CLR-based trigger to make an external call when needed, to a program that starts the desired process asynchronously (so, outside the transaction that ...
5
The "geospatial feature" of dynamodb isn't really anything else then calculating a geohash from the coordinates, storing the hash in the same row, create an index on the hash, and when querying based on a location, calculate the hash of that location and compare to the indexed hashes in the table. The algorithm of geohash is really simple and with a ...
5
Duplication isn't ideal, but in this case is probably the best choice. Set the table permissions so that the table owner is not the operational day to day database user your app runs as, and only GRANT your app the ability to write to the certificate data column, not the "cache" columns with expiry etc. Have a SECURITY DEFINER trigger function intercept ...
answered Mar 11 '13 at 11:46
Craig Ringer
47.9k33 gold badges123123 silver badges160160 bronze badges
5
I cannot see any possible way for this to work given that the script is being submitted through a back-end service where there is no user-context (i.e. display, etc). SSMS is not executing anything. It is merely submitting those statements to SQL Server which handles the execution (even if SQL Server then passes it off to something else).
The only potential ...
answered Jan 24 '18 at 19:08
Solomon Rutzky
61.7k66 gold badges126126 silver badges253253 bronze badges
5
Pyodbc won't progress past info messages automatically, and RESTORE generates a lot of them. So you must process them with cursor.nextset() or else you're actually aborting the RESTORE by running cursor.close() before it actually completes.
Eg
cursor.execute(sql)
while cursor.nextset():
pass
cursor.close()
answered Aug 21 '20 at 19:26
David Browne - Microsoft
30.3k22 gold badges3232 silver badges6767 bronze badges
5
I am able to get identical results between python and T-SQL code with the MD5 algorithm. For example, the NO COLLUSION string hashes to 0x5CA1A58C070F24EF1D4D2900E5727F37 on both platforms.
Example T-SQL code:
SELECT HASHBYTES('MD5', 'NO COLLUSION');
Example Python code:
import hashlib
result = hashlib.md5(b'NO COLLUSION')
print(result.hexdigest())
I'm not ...
5
Joe has correctly pointed out that Python's hashlib.md5 and SQL Server's HASHBYTES('MD5', ...) functions have the same output.
As an additional clarification, the built-in hash() function in Python is not intended to be used in the same way. It's implementation is platform specific, varies depending on the type of object being used, and is (as you mentioned)...
5
my other colleague categorically stated that using CLR here would be a huge risk to security and stability
Well, your colleague is categorically wrong (unless they can offer up actual proof of such claims).
Security
Ever since SQLCLR was introduced in SQL Server 2005 people have been saying that it is "unsafe". However, I have yet to see anyone ...
4
The package to install is postgresql-plpython3.
By way of dependencies, this will install postgresql-plpython3-9.1, which provides these files:
$ dpkg -L postgresql-plpython3-9.1
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/postgresql-plpython3-9.1
/usr/share/doc/postgresql-plpython3-9.1/copyright
/usr/share/postgresql
/usr/share/postgresql/9.1
/usr/...
4
Set the Application Name
If you expect to be running many processes you need to know where they are
connecting from. PGBouncer will make this invisible to pg_stat_activity. Solve
this by carefully setting the application_name with the information you'll
need:
# Sets the application name for this connection in the form of
# application-name:user@host
prog ...
4
I did some experimentation in console trying to figure out why this was happening for me as well. In the end, I searched right into the file folder for the package looking to ensure that the pooling file was present in the mysql.connector package version I had.
Sure enough there it was.
In the end, I simply changed my import statement. I had been using
...
4
I have some theories as to why the performance is so bad.
Lets see.
The first is that I simply have too many rows.
Probably not. There is no limit on the number of rows in a (SQL) DBMS. 80 million rows is not that much these days.
The second is that a database is not suited for this task.
Unlikely. We don't know which DBMS you use (Postgres? ...
answered Nov 10 '17 at 12:21
ypercubeᵀᴹ
88.6k1212 gold badges170170 silver badges261261 bronze badges
4
Use the following parameter to set the number of maximum connections from your pymongo app.
client = MongoClient(host, port, maxPoolSize=10)
Here is documentation with more details.
4
I tried to fix this by submitting a patch #234 (approved but not yet committed). You'll have to edit the file ~/.local/bin/mssql-cli and replace
python -m mssqlcli.main "$@"
With this line
( command -v python3 && python3 -m mssqlcli.main "$@" ) || python -m mssqlcli.main "$@"
answered Jan 28 '19 at 17:35
Evan Carroll
48.6k2727 gold badges165165 silver badges354354 bronze badges
3
The fact that MySQL locks behave this way by default seems perverse to me, but that's not the point.
Actually, that's totally the point, because locks from SELECT statements is something MySQL doesn't ordinarily do... so by some as-yet-unknown mechanism, you've asked it to do that.
The most likely explanation is that you (or whatever you are using as a ...
3
DISCLAIMER : Not a Python Programmer
I can give you a generic algorithm
Let's say you have 4 DB Servers
replicator@10.1.2.% is the Replication User
1 Master (10.1.2.10)
3 Slaves (IP Addresses : 10.1.2.20,10.1.2.30,10.1.2.40)
STEP 01) Run this query
SELECT host FROM information_schema.processlist WHERE user = 'replicator';
Collect host columns into a ...
answered Feb 12 '13 at 3:27
RolandoMySQLDBA
163k2929 gold badges269269 silver badges459459 bronze badges
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
python × 221postgresql × 77
mysql × 58
sql-server × 26
mongodb × 21
sqlite × 15
sql-server-2017 × 9
sqlalchemy × 9
database-design × 7
mariadb × 6
ubuntu × 6
odbc × 5
django × 5
oracle × 4
performance × 4
backup × 4
stored-procedures × 4
trigger × 4
db2 × 4
json × 4
aws × 4
csv × 4
utf-8 × 4
plpython × 4
innodb × 3