how can i change the "character type" of a database in postgresql? - postgresql

I'm using postgreSQL 9.1
I've set the Collation and the Character Type of the database to Greek_Greece.1253 and I want to change it to utf8
To change the collation I should use this, right?
But how can I change the character type?
Thanks
EDIT
I ment to wright C instead of utf8. I would like to change the Collation and the Character Type to C

You cannot change default collation of an existing database. You need to CREATE DATABASE with the collation you need and then dump/restore your schema and data into it.
If you do not want to recreate the database - you can specify collation for every text collumn in your db.
Here is detailed postgres manual on collations: Collation Support.
First line of this manual page states:
LC_COLLATE and LC_CTYPE settings of a database cannot be changed after
its creation.
CREATE DATABASE, pg_dump, pg_restore

Related

Create database defnition equivalent from mysql to postgresql

I need to migrate a mysql table to postgresql.
I need an accent and case insensitive database.
In mysql, my database has the next definition:
CREATE DATABASE gestan
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
How do I create an equivalent definition to postgresql?
I have read some posts, but it seems outdated.
create database getan
encoding = 'UTF-8';
There is no direct equivalent for the case insensitive collation _ci in Postgres.
You can define a new ICU collation that uses case insensitive comparison, but it can't be used as a default collation for a database, only for the collation on column level.
Related questions:
Install utf8 collation in PostgreSQL
https://dba.stackexchange.com/questions/183355
https://dba.stackexchange.com/a/256979

restore the database to a different collation

I tried to find how do I restore the database to a different collation.
For example:
Server collation is Czech_CI_AS
Database, which I backed up, has a collation Czech_CI_AS.
And I need to restore a backup of the database, but with the
collation SQL_Latin1_General_CP437_CI_AI.
Somewhere I'm doing something wrong, will you help me?
As you've discovered, the collation of the original database is preserved in the backup, and so when you create a new database from this backup somewhere else, the original collation comes with it. There is no option on the restore command to change collation during the restore.
You could ALTER DATABASE to a different collation after you have restored the database, but note that this will not change the collation of all the existing objects in the database, you will need to alter the collation of columns in individual tables yourself.
See MSDN:
When you change the database collation, you change the following:
Any char, varchar, text, nchar, nvarchar, or ntext columns in system tables are changed to the new collation.
All existing char, varchar, text, nchar, nvarchar, or ntext parameters and scalar return values for stored procedures and
user-defined functions are changed to the new collation.
The char, varchar, text, nchar, nvarchar, or ntext system data types, and all user-defined data types based on these system data
types, are changed to the new default collation.
You can change the collation of any new objects that are created in a
user database by using the COLLATE clause of the ALTER DATABASE
statement. This statement does not change the collation of the columns
in any existing user-defined tables. These can be changed by using the
COLLATE clause of ALTER TABLE.

Is it safe to change Collation on Postgres (keeping encoding)?

I have a Postgres 9.3 database which, by mistake, has been set to:
but I need it to be:
Since the Encoding doesn't change, it is safe to dump the DB and restore it later (see here) to a database with the new Collation / Character type?
Perfectly safe -- the collation is just telling Postgres which set of rules to apply when sorting text.
You can even set it dynamically on a query basis in the order by clause, and should be able to alter it without needing to dump the database.

How to add collations UNICODE_CI/_AI to an old database

I have an old database running on a Firebird 2.5 server, on which is missing the collations UNICODE_AI and UNICODE_CI. Direct selection on meta tables is indicating this.
select * from RDB$COLLATIONS where rdb$collation_name like 'U%'
returns UNICODE, UNICODE_FSS, UTF8 and UCS_BASIC.
How can I add these collation to my current database?
Doing a backup restore of the meta table solve the issue.

firebird set case insensitive collation

How can I set case insensitive collation for the whole database?
Do I have to recreate the tables and data?
Database is firebird 2.5
Quote from the release notes:
The character set and collation of existing columns are not affected by ALTER CHARACTER SET changes.
So yes, it seems that the best way would be to recreate the database with desired default character set and collation (and / or with explicit definitions in domains).