- 论坛徽章:
- 0
|
In your target Postgres tables, define your GUID fields as either char(36) or varchar(36).
In your SELECT from SQL Server, you will want to strip the '{}' characters from the source data.
To generate new GUID values, you will need to create a Postgres user defined function (like 'new_uuid()') to return a varchar value. An MS-like GUID can be created by hashing together your server's MAC address with a timestamp. The md5 function can be used to do this easily like this:
vWork1 := md5(vMAC || now());
vWork2 := SUBSTRING(vWork1, 1, 8) ||'-'|| SUBSTRING(vWork1,9,4) ||'-'|| SUBSTRING(vWork1,13,4) ||'-'|| SUBSTRING(vWork1,17,4) ||'-'|| SUSTRING(vWork1,21,12);
RETURN cast(vWork2 as varchar(36));
I'm doing this off the top of my head, but the code above is very much like implementations that I have done on my own Postgres instances.
这是我看到的一个鸟语帖子。哪个哥哥可以帮写出一段完成的new_uuid函数的定义。
我的CREATE FUNCTION "New_Uuid"() RETURNS "char" AS
'vWork1 := md5(vMAC || now());
vWork2 := SUBSTRING(vWork1, 1, 8) ||\'-\'|| SUBSTRING(vWork1,9,4) ||\'-\'|| SUBSTRING(vWork1,13,4) ||\'-\'|| SUBSTRING(vWork1,17,4) ||\'-\'|| SUSTRING(vWork1,21,12);
RETURN cast(vWork2 as varchar(36));
'
LANGUAGE 'sql' VOLATILE; 总是要报错ERROR: syntax error at or near "vWork1" at character 1 |
|