All posts by kortsi
Upsert Methods for PostgreSQL
Update: PostgreSQL 9.5 has been released with INSERT .. ON CONFLICT UPDATE support.
PostgreSQL has no “upsert” or “replace” or “insert .. on duplicate key update” or “merge into” construct to conditionally either insert a new row, or if a row with the key already exists, to either update the existing row with the new values, or first delete the old row and then insert a new one. This has been discussed many times in the posgresql developers mailing lists, and plans to implement the SQL standard MERGE operation have been devised. But there is still no such functionality in PostgreSQL as of version 9.3. Here are some examples on how to implement the functionality in different ways, using either a function, a trigger function or a rule. None of them are perfect. There are trade-offs to be made. Continue reading Upsert Methods for PostgreSQL
SQLAlchemy Declarative Class Reflector
SQLAlchemy has a nice reflection facility which takes for example a database table name as argument and produces a Table object out of it for manipulation. However, those objects do not behave like the objects produced by declarative classes, which are easier to work with. Here’s a little class that helps to bridge that gap by reflecting proper declarative classes from database tables. It has only been tested with PostgreSQL, but it may work with other databases as well. Continue reading SQLAlchemy Declarative Class Reflector
Editing Tabular Data in Vim
Helpful settings for editing tabular data:
1 2 3 |
setlocal noexpandtab setlocal nowrap setlocal tabstop=16 softtabstop=16 shiftwidth=16 |
Noexpandtab disables expanding of inputted tabs to spaces. Adjust the number of spaces to your liking. Tabstop sets the visual appearance of tab stops (here 16 spaces). Continue reading Editing Tabular Data in Vim
Use Vim as Info Page Browser
LDAP Authentication and NSCD
Verifying Back-End Calls from Android Apps
Ignoring files · GitHub Help · Global .gitignore
Ignoring files · GitHub Help · Global .gitignore
Configuring Apache, Nginx, and OpenSSL for Forward Secrecy
Secrets of tabs in vim
How to import existing GIT repository into another?
Developer Mode for the Samsung Galaxy S4
From: Developer Mode for the Samsung Galaxy S4
Get to the phone’s settings by tapping ‘menu’ from the home screen and then tapping ‘settings’
- tap on ‘more’
- tap on ‘software information’
- tap on ‘About Device’
- find the build number, and tap it 7 times
- on the 7th tap, a prompt should appear alerting you that Developer Options has been unlocked
You may also wish to:
1 2 3 |
android update adb adb kill-server adb start-server |
And after that you must accept the USB connection by tapping OK in the prompt on the device after you connect it.
How to install PostgreSQL 9.2 on Ubuntu 13.04
Set Default search_path for a User in PostgreSQL
Here’s how to do it:
1 |
ALTER ROLE myuser IN DATABASE mydb SET search_path = myschema; |
The same syntax works for any configuration parameter, such as localization parameters.
How to prefer IPv4 over IPv6 for some hosts
If an IPv6 address is unreachable, but you can reach the IPv4 one, you can set the preference to IPv4 for that particular address by adding a line such as this in /etc/gai.conf:
1 |
precedence ::ffff:198.145.11.105/128 100 |
That will set the preference for host 198.145.11.105 to IPv4.
See gai.conf(5) for details.